Using group sys id in client script. Want to Convert group sys id into System Properties

Krishna Priya
Tera Contributor

I have catalog client script that uses group id and display variable based on group member on RITM and Task. I want to convert sys id into System Properties. 

 

I used below Business rule and Client script. But not able to achieve this. Is below script is correct ? What table name do i need to use in business rule?

 

Business rule: 

 When  - before
Table name?
any other conditions in when to run ?
 

 

(function executeRule(current, previous /*null when async*/) {
    g_scratchpad.my_property = gs.getProperty('sysid.assignment_group');
})(current, previous);

 

 
Catalog client script: 
Type: onLoad
Applies on Requested Items
Applies on Catalog Tasks

 

function onLoad() {
   
    var u_user_id = g_user.userID;
    var u_grp_id = g_scratchpad.my_property
        getgroupUsrMembership(u_user_id, u_grp_id);
}

function getgroupUsrMembership(u_userID, u_grpID) {
    var gaX2 = new GlideAjax('Tools');
    gaX2.addParam('sysparm_name', 'checkUserMemberOfGroup');
    gaX2.addParam('sysparm_usr', u_userID);
    gaX2.addParam('sysparm_grp', u_grpID);
    gaX2.getXMLAnswer(processLoad);

}

function processLoad(answer) {
    var u_ismember;
    if (answer == "false") {
        u_ismember = false;
        g_form.setMandatory('variables.approval', false);
        g_form.setDisplay('variables.approval', false);
    } else {
        u_ismember = true;
        if (g_form.ui_policy && g_form.ui_policy.approvals)
            g_form.setDisplay('variables.approval', true);
    }
   
}

 

 
 
2 REPLIES 2

DanielCordick
Mega Patron
Mega Patron

Hi Krishna

 

you can only define scratchpad in a  display business rule

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response helped in any way 

Sagar Pagar
Tera Patron

Hi @Krishna Priya,

 

The g_scratchpad variables only wok in display business rule.

 

You need to use the script include and onload/ on change client scripts.

Take a look at one of my article. It will help you.

System Properties & it's Usage 


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow