Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Validate group member with lodged in user and set field value make read only

vinnus
Tera Contributor

GIVEN the user is a member of the a​  group and check user is current logged in user 
WHEN the user opens the record producer then Field one choice set to specific value and make field ready only

2 REPLIES 2

PradeepReddyA
Tera Guru

Hi @vinnus 

 

You can call the call the script include using GlideAjax in the catalog client script and in the script inlcude enable the GlideAjax enabled checkbox to true

Client script:

function onLoad() {

 

var ga = new GlideAjax('CheckUserGroup');
ga.getXMLAnswer(function(answer) {

if (answer === 'true') {

// Set Field 1 to the required choice value
g_form.setValue('field_one', 'specific_value');

// Make Field 1 read-only
g_form.setReadOnly('field_one', true);
}
});
}

 

Script include:

var CheckUserGroup = Class.create();
CheckUserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {

isUserMember: function() {

var isMember = gs.getUser().isMemberOf('GROUP_SYS_ID');

return isMember;
},

type: 'CheckUserGroup'
});

iftekhar_mirza
Tera Guru

Hi @vinnus ,

To achieve this requirement, we can use an onLoad Catalog Client Script along with a Client Callable Script Include.

1. Catalog Client Script

Use an onLoad Catalog Client Script on the Record Producer.

The script checks whether the logged-in user belongs to the required group. If the user is a member:

  • Set Field 1 to the required choice value in my case setting the value to "Choice 2".
  • Make Field 1 read-only.
    iftekhar_mirza_0-1787565925930.png

    iftekhar_mirza_2-1787565963183.png

    2. Client Callable Script Include

    Since the group membership needs to be validated against sys_user_grmember, use a Client Callable Script Include:

    iftekhar_mirza_3-1787566072305.png

    Result :

     Populating the logged in user on the "Assigned to" field and updating the choice field

    iftekhar_mirza_4-1787566171894.png

    Please check below screenshots

    Please mark my answer as helpful/correct if it resolves your query.

    Regards,

    Iftekhar