How to pass Service Request Catalog User Selection value in an Approval Definition function call

I'm trying to pass the value of a user selection to an Approval Definition that uses a function call.  I've verified that the function works by hard-coding the parameter value in the script, but it passes the name of the user selection rather than the value when I try to pass it in as a parameter.

The function call in the Approval Defintion condition:

jscall("xcelSRCUNIXGroupUtils.PrivAccessCheck", "xcelSRCGenericTypeOne in $File")="yes"

returns

08/29/18 09:25:31 xcelSRCGenericTypeOne in $File
08/29/18 09:25:31 xce
08/29/18 09:25:31 no

I receive an error if I don't put the parameter in quotes.

Below is the function

function PrivAccessCheck(unixGroupName)
{
var PrivAccess="no";
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);
}

 

  • Verified Answer

    I have one approval definition which calls JS lib.

    jscall("GetManager.IsApprovalNeeded", nullsub(contact.name in $L.file, requested.for in $L.file))=true

    But I'd like to point out that both fields are actual fields in incidents table. I can't refer straight away to a single user option. Why?

    User selections are not actual fields in SD ticket. User selections are bundled into XML format to the field called svc.options. At a first sight, this is quite confusing, but product designers have reasonably thought that it gives the maximum flexibility but minimizes the need to create dozens of DB fields for catalog purposes. 

    Check a SD ticket (type: service catalog) and use RAD debugger to print out:

    d svc.options in $L.file

    The output should be XML code. You can't refer to a certain XML item in a similar way than to a single "real" field in a DB such as incident.id or title. You need some JS code to go though the XML tree and pick the correct values.

    What I recommend is that you pass the $L.file to your JS code, print it to the log in a code and check what data it has eaten by then. If svc.options is already populated, you can clearly spot the XML code from the log output.

    After then, it's time to think how to carve out the XML tag and its content, but this forum contains many fresh topics about it.

    EDIT: If you have a version 9.40 or later, there's also a table called userOption, that actually renders all the user selections items as a proper DB items. OOB version of SM does not offer forms to browse it, so use DB tool to check its contents and you get a grasp what fields you need in your query.

  • Thanks for the excellent explanation.  I have it working now.

  • Please send me exact steps to solve this issue