Make variables read only after group approval stage (RITM)

rafaelalves4337
Tera Contributor

Hello folks,

 

I have created a Script include and Client script to make 2 variables editable after user submit, so the approval team can make changes and assign a better group team to work, it's all working fine so far, the problem now is, those variables still editable even after the approval stage is Approved, I have tried some variations here but still not finding a solution, below is the client script I'm using, could you please help me this situation?

 

function onLoad() {
   //Type appropriate comment here, and begin script below
   
    var number = g_form.getValue('number');
    var ga = new GlideAjax('XXXXXXXX');
    ga.addParam('sysparm_name', 'fetchDataweb');
    ga.addParam('sysparm_name_number', number);

    ga.getXML(callback);

    function callback(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
        if (answer == 'Client XXXX') {
			
			g_form.setReadOnly('target_date', false);
			g_form.setReadOnly('all_assin_group',false);

			g_form.setMandatory('all_assin_group', true);
}

 

6 REPLIES 6

JenniferRah
Mega Sage

I think a simpler way to accomplish this would be to use a UI Policy. You can add script in there if needed and check the value of the "stage" field and determine whether to allow the variable(s) to be editable or not.

Mihir Mohanta
Kilo Sage

Add some more conditions in the client script to validate approval stage. If approval stage == approved don't call the script include from the client script.

 

If it is not possible to validate approval stage in client you can alternatively add the validation condition in the script include.

Ankur Bawiskar
Tera Patron
Tera Patron

@rafaelalves4337 

you can add condition for state on approval record on your table

your client script is on which table?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

The table is Sc_req_item.

 

I was able to change the script and now it is read only again after approval.

 

Now I have another issue, the variable Assignment Group is mandatory, but if the approver goes to service portal and click approve, it is approving even with that field empty, do you know how can I prevent the user to approve when that field is not populated?