This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Variable handling

Variable handling
I am programming a script in appscript.
executes in an action in an SBM form. the execution ends in the execution of a .bat with parameters.
The first inconvenience is the value of one of these variables (description,of type text), which is a text field with spaces and the .bat receives x number of parameters, I need to send all of these as one, I tried several options but they didn't work for me. the second drawback is handling with dates. (fecha_inicio of type datetime)
and the third is the user who started the workflow(requested_byof type user)

I share my code, any contribution will be very well received. thank you

Option Explicit
' --------------------------------------
const rp_id = "ISSUEID"
const cmdb_ci = "TMPSIGLA"
const description = "DESCRIPTION"
const fecha_inicio = "TEMP_SCHEDULE_START_DATE"
const requested_by = "RLM_DEVELOPER"
' Name of the field we will work with
' ------------------------------------
' Path to the .BAT file
const SCRIPT = "D:\Serena\Scripts\Service-now\crear.bat"


' Gather params from item fields, pass them to .BAT file.
Sub LaunchBatchFile()

Dim exitCode, irp_id, icmdb_ci, idescription, ifecha_inicio, irequested_by

Call Shell.Item.GetFieldValue( rp_id, irp_id)
Call Shell.Item.GetFieldValue( cmdb_ci, icmdb_ci)
Call Shell.Item.GetFieldValue( cmdb_ci, idescription)
Call Shell.Item.GetFieldValue( requested_by, irequested_by)
Call Shell.Item.GetFieldValue( fecha_inicio, ifecha_inicio)

' Run the .BAT file with params
exitCode = Ext.NewTaskWait(SCRIPT, irp_id, icmdb_ci, idescription)

End Sub


  • Suggested Answer

    The "requested_by" field will contain the TS_ID of the user.  If you want the user's name, loginID or email you will need to get it from TS_USERS.

    For the date field, try using the VBScript "FormatDateTime" function to convert it to a string.

    The "Description" field needs to have control characters escaped.  Below is some code I use to do that. The was originally in an SQL script and I've modified it for VBScript.  Hopefully it doesn't cause any "line too long" problems.  The code handles some system fields in the TS_REPORTS table so it has conversions for the SOH, STX and ETX characters.

    ' Fix a string that may contain quotes or other ASCII chars.
    '     Used to clean up fields read from TS_REPORTS, among other things.
    Function EscapeString(str)
       EscapeString = _
          Replace(  _
             Replace(  _
                Replace(  _
                   Replace(  _
                      Replace(  _
                         Replace(  _
                            Replace(  _
                               Replace(  _
                                  Replace(  _
                                     Replace(  _
                                        Replace(  _
                                           Replace(  _
                                              Replace(  _
                                                 Replace(  _
                                                    Replace(str , Chr(7) , "\bel"),  _
                                                 Chr(8),"\bs"),  _
                                              Chr(9),"\t"),  _
                                           Chr(10),"\n"),  _
                                        Chr(11),"\vt"),  _
                                     Chr(12),"\ff"),  _
                                  Chr(13),"\r"),  _
                               Chr(34),"""),  _
                            Chr(39),"'"),  _
                         Chr(60),"<"),  _
                      Chr(62),">"),  _
                   Chr(96),"`"),  _
                Chr(1),"{SOH}"),  _
             Chr(2),"{STX}"),  _