Show/Hide sc_task fields on task form

HMR00
Tera Contributor

Hi, 

 

i am working on a client script to show "stage" field (custom field) and hide "status" field on sc_task form for a particular assignment group and reverse the condition for all others. attached client is working in one environment and once moved onto another ENV thru update set it is not working ? Can some1 help troubleshoot this ?

 

2nd requirement is i need to trigger a notification if task is in "pending" state for 48 hours ? any direction how to achieve this preferably in wokflow studio -> Flow !

2 REPLIES 2

SanjanaK
Tera Expert

Hello @HMR00 

 

You can try re-testing it in your first environment and check whether it actually worked there? because I believe we don't have g_user.isMemberOf() function in client.
So workaround is to create a scratchpad variable in Business Rule to check if the user is member of group and use that scratchpad variable here in Client Script.

1) You can create a Display BR on same table and write below script

g_scratchpad.checkMember = gs.getUser().isMemberOf(group_sys_id);

 

2) Use this in your Client Script where u wanted to check isMemberOf()

so in your code at line 5 we can write:

 

if (g_scratchpad.checkMember)

      //Your code

else

     //Your code

 

3) Best Practice: Instead of hardcoding the sys_id in your script, we can create a system property storing this value and use this property wherever required.

 

****************************************************************

Hope the answer help!

Happy Learning!

 

Nishant8
Giga Sage

Hello @HMR00, isMemberOf() isn't available on the client side. If you'd like to validate whether a user is part of a group, one approach you can try is defining a client-callable Script Include along with a Client Script. I'm sharing both below for your reference.

- Script Include (ensure its client callable)

var TestCheckuserGroup = Class.create();
TestCheckuserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    checkGroup: function() {
        var userSysId = this.getParameter('sysparm_user_sysid'); // coming from client script
        var supportTeamSysID = 'b85d44954a3623120004689b2d5dd60a'; //replace with you group sys ID
        var grGroup = new GlideRecord('sys_user_grmember');
        grGroup.addQuery('user', userSysId);
        grGroup.addQuery('group', supportTeamSysID);
        grGroup.query();
        return grGroup.hasNext();
    },
    type: 'TestCheckuserGroup'
});

- Client Script: you can include your desired fields in if and else block accordingly

function onLoad() {
    var ga = new GlideAjax('global.TestCheckuserGroup'); //script include name
    ga.addParam('sysparm_name', 'checkGroup'); //function name
    ga.addParam('sysparm_user_sysid', g_user.userID); //passing userID to server
    ga.getXMLAnswer(checkGroup);
    function checkGroup(response) {
        if (response == 'true') {
            g_form.setDisplay('state', false);
        } else {
           g_form.setDisplay('state', true);
        }
    }
}

 

For Requirement 2: yes, you can achieve it easily with help of Flow Designer. You can define FD as attached below. You can make necessary changes according to your requirement for e.g. schedule to run as required.

Its assumed that task is not modified since its moved to pending state. if there is a possibility that task might be updated in between and you want to calculate hours since its moved to pending, then you can populate a field when task moves to pending and use that field in lookup than updated.

Nishant8_0-1750853745630.pngNishant8_1-1750853898046.png

 

 

Regards,

Nishant