Troubleshooting/view print statement output from script called by SRC Approval Definitions

I'm trying to set up an Approval Defintion in Service Request Catalog that will call a javascript function in the script library, using the value of one of the User Selections as a parameter.  I'm running into two problems:

1.  The approval is never set, even if I hard code a value in the javascript funciton

2.  I don't know how/where to see the output from print statements in the javascript function.

The function call in the approval definition (xcelSRCGenericTypeOne is a User Selection field name):

jscall("xcelSRCUNIXGroupUtils.PrivAccessCheck", "xcelSRCGenericTypeOne")="yes"

The javascript function:

function PrivAccessCheck(unixGroupName)

{

var PrivAccess="no";

unixGroupName="ug-esb-dev-xdev"

print("unixGroupName= " unixGroupName);

var unixGroupPreFix = unixGroupName.substring(0,2);

print("unixGroupPreFix = " unixGroupPreFix);

if ( unixGroupPreFix == "ug-" )

{

PrivAccess="yes"

}

return PrivAccess;

}

  • Those kind of print messages will only be seen in the Messages windows of the User that triggers that code.

    You probably want to write your print statements to the sm.log, so in Javascript, it'll be something like:

    system.vars.$L_void = system.functions.rtecall("log", system.vars.$L_rc, "unixGroupName= " unixGroupName);

  • Set all static in the approval definition and see if it works. If it works, change back to your code and show us a print of your definition.
  • Thanks for your response.  I've made some updates and received output in the sm.log file.  From the output, it looks like the script is working, but the approval condition isn't firing.

    Output:

    08/28/18 14:04:55 ug-esb-dev-xdev
    08/28/18 14:04:55 ug
    08/28/18 14:04:55 no

    New Script:

    function PrivAccessCheck(unixGroupName)

    {

    var PrivAccess="no";

    unixGroupName="ug-esb-dev-xdev"

    print("unixGroupName= " unixGroupName);

    smLogPrint(unixGroupName);

    var unixGroupPreFix = unixGroupName.substring(0,2);

    print("unixGroupPreFix = " unixGroupPreFix);

    smLogPrint(unixGroupPreFix);

    if ( unixGroupPreFix == "ug-" )

    {

    PrivAccess="yes";

    }

    print("PrivAccess = " PrivAccess);

    smLogPrint(PrivAccess);

    return PrivAccess;

    }

    function smLogPrint(val)

    {

    print(val);

    writeFile("../logs/sm.log","a","\n" system.functions.str(system.functions.tod()) "\t" val); 

    }

  • Verified Answer

    I just realized the script is returning no when it should return yes.  Sorry - should have checked before I posted.

  • OK, now it works!  I had the substr values wrong (again, I think).

    function PrivAccessCheck(unixGroupName)

     {

    var PrivAccess="no";

    unixGroupName="ug-esb-dev-xdev"

     smLogPrint(unixGroupName);

    var unixGroupPreFix = unixGroupName.substring(0,3);

    smLogPrint(unixGroupPreFix);

    if ( unixGroupPreFix == "ug-" )

    {

    PrivAccess="yes";

    }

    smLogPrint(PrivAccess);

    return PrivAccess;

    }

    function smLogPrint(val)

    {

    print(val);

    writeFile("../logs/sm.log","a","\n" system.functions.str(system.functions.tod()) "\t" val);

    }