7 Replies Latest reply on Jul 17, 2018 3:12 PM by WARRIOR

    HOW TO EVALUATE STRING VARIABLES IN A WEB SERVICE.

    WARRIOR Apprentice

      I just found out that SubString(), SubString0(), Find(), IndexOf(), Decode, and so much more sting and system functions do not work in the web service environment.

       

       

       

      How do you perform string variable evaluations in the ISM web service environment?

       

       

      What I really need is SubString(), or something similar. I tried to implement a while loop so I can extract each character, but that did not work, as I did not know how to extract each character wither, which by default means substring.

        • 1. Re: HOW TO EVALUATE STRING VARIABLES IN A WEB SERVICE.
          Jonathan.Schmidt SupportEmployee

          Hi Warrior,

           

          Can you elaborate?  Are you writing expressions in the ISM system or writing a web service integration?

           

          For Expressions, the help file has these functions available: String Functions

          For the web service integrations, I usually recommend this guide as a starting point (though I do not know if the examples contain any string manipulation) Ivanti Service Manager Web Services.pdf

           

          Jon

          • 2. Re: HOW TO EVALUATE STRING VARIABLES IN A WEB SERVICE.
            WARRIOR Apprentice

            Hey Jon,

             

            The web service environment behaves a little different.

             

            it does not see the contents of table cells (that is the specific column of a row of data). Instead, it sees the object definition. It is therefore unable to perform string variable evaluations. Some sort of evaluation may be possible if the object being reviewed is a dynamically created JSON structure.

             

            When you attempt to invoke traditional string functions (like substring, decode, find, etc.) mentioned in the URL you posted, it errors out as these are foreign to the internal webservice environment.

            • 3. Re: HOW TO EVALUATE STRING VARIABLES IN A WEB SERVICE.
              BKallweit Apprentice

              Hi Warrior,

               

              when writing web service scripts you should be able to use the usual javascript methods, e.g. JavaScript String Methods

               

               

              Best

              Bernd

              • 4. Re: HOW TO EVALUATE STRING VARIABLES IN A WEB SERVICE.
                WARRIOR Apprentice

                Hi BKallweit,

                 

                 

                It makes sense that if one is able to dynamically define a variable as is the case in the documentation provided by the link you posted.

                 

                 

                in javascript:

                 

                          var myStr = "This is a string variable"

                 

                     is different from:

                 

                          var myRef = referenceTableSearchResult.Fields.TargetFieldName

                 

                 

                The former explicitly holds the assigned value, while the later is a pointer to the memory location where the object is stored. The later is therefore not the value, and may not necessarily know what kind of object the pointer is pointing to.

                 

                To be able to explicitly pass the content of the former by value, there has to be a function that returns the value. Something like reference TableSearchResult.Fields.TargetFieldName.Value

                • 5. Re: HOW TO EVALUATE STRING VARIABLES IN A WEB SERVICE.
                  WARRIOR Apprentice

                  I have a work around that seems to work:

                   

                   

                  1. Create a field for monitoring changes,
                  2. Create a business rule (trigger) that monitors the field in (1) above for a specific change in value, and performs string evaluation as needed
                  3. Then use the web service to address the other needs.

                   

                   

                  By doing the above, I succeeded in creating an artificial loop which though may be resource intensive, but meets my need for now, until I find a more elegant way to address this problem.

                   

                  Please note that this is not a solution, but a work around. A preferred solution would be to find a way to acquire the field value directly. I already tried referenceTableSearchResults.FieldValues[0].Value, and it did not seem to work.

                  • 6. Re: HOW TO EVALUATE STRING VARIABLES IN A WEB SERVICE.
                    crispr_bacon Rookie

                    I had no issues using any of the string functions in webservices.

                     

                    console.info("\n</br>--Script Starting-- v.1.4</br>\n");

                    try{

                    var curIncident = Get('Incident#', '$(RecId)');

                    var curIncNumber = curIncident.Fields["IncidentNumber"];

                    var curIncSubject = curIncident.Fields["Subject"];

                    var testLen = curIncSubject.length;

                    var testIndex = curIncSubject.indexOf("access");

                    var testLastIndex = curIncSubject.lastIndexOf("access");

                    var testSearch = curIncSubject.search("access");

                    var testSlice = curIncSubject.slice(7,13);

                    var testSubstring = curIncSubject.substring(7,13);

                    var testSubstr = curIncSubject.substr(7,6);

                     

                    console.info("1. Retrieved Incident Info for Inc# " + curIncNumber + "</br>");

                    var employee = Get('Employee#', '$(CurrentUserRecId())');

                    console.debug("2. Retrieved Employee Info</br>");

                     

                    var newComment1 = Create("Journal#Notes");

                    newComment1.Update({

                    "NotesBody" : curIncNumber + "\n" + curIncSubject + "\n" + testLen + "\n" + testIndex + "\n" + testLastIndex +

                    "\n" + testSearch + "\n" + testSlice + "\n" + testSubstring + "\n" + testSubstr ,

                    "ParentLink_Category" : "Incident",

                    "ParentLink_RecID" : "$(RecId)"

                    });

                    console.debug("3. Note Written</br>");

                    } catch (err) {

                    console.debug("\n ERROR... " + err.message + "</br>");

                    var ErrorNote = Create("Journal#Notes");

                    ErrorNote.Update({

                    "NotesBody" : "Error: " + err.message,

                    "ParentLink_Category" : "Incident",

                    "ParentLink_RecID" : "$(RecId)"

                    });

                    }

                     

                    1 of 1 people found this helpful
                    • 7. Re: HOW TO EVALUATE STRING VARIABLES IN A WEB SERVICE.
                      WARRIOR Apprentice

                      We actually found out shortly after my last posting that the problem was that we were trying to perform the string evaluation on the business object field value directly, which was the reason we ran into issues. Below is what we were doing:

                       

                       

                                var MyVariable = <BusinessObject>.Fields.<FieldName>.substring(1, 5);

                       

                       

                      This would have worked in any other programing environment, but it failed here. Instead we did:

                       

                       

                                var MyVariable = <BusinessObject>.Fields.<FieldName>;

                       

                       

                                var AnotherVariable = MyVariable.substring(1, 5);

                       

                       

                      This worked and avoided the work around with multiple triggers.