Script include to query a record and set the value of specific field

Sri56
Tera Contributor

Hi Team,

We need a script include to query 'sysapproval_approver' table and check if approval type is parallel.

For those records, we need to set the field 'parallel approvals intiated' as true from client script by calling above script include.

below screenshot is for your reference:

find_real_file.png

Please help with the code

Thanks,

Sri

 

34 REPLIES 34

Are you initiating this from a task form ?

Hi,

Nope, this has written on sysapproval table.

Please help!

 

Thanks,

Sri

Can we please have a call?

I can explain you in brief!

This is quite urgent!

Thanks,

Sri

Sri56
Tera Contributor

Hi Muhammed,

Can you please help on this?

Thanks,

Sri

Mahendra RC
Mega Sage

Hello,

Please check if below helps you:

Put the below script in your client script onLoad, onChange or onSUbmit as per your need:

if (newValue) {
        var ga = new GlideAjax('CustomApprovalUtils');
        ga.addParam('sysparm_name', 'updateApprovalRecord');
        ga.getXMLAnswer(parseRecievedResponse);
    } 

	function parseRecievedResponse(answer) {
		if (answer) {
			alert("APPROVAL RECORD UPDATED");
		}
	}

Script INclude where client callable is checked, I am not sure if this will work because if some user who is not having access to update the Approval record and that user tries to execute the update the I think ACL will restrict. You can check once and confirm

var CustomApprovalUtils = Class.create();
CustomApprovalUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	updateApprovalRecord: function() {
        var recordUpdated = "";
        var sysApprovalGR = new GlideRecord('sysapproval_approver');
		sysApprovalGR.addEncodedQueryQuery('PUT YOUR QUERY');
		sysApprovalGR.query();
		while(sysApprovalGR.next()){
			sysApprovalGR.setValue('<parallel_approvals_initiated_field_name>', true);
			recordUpdated = sysApprovalGR.update();
		}
		return recordUpdated;
	}
    type: 'CustomApprovalUtils'
});

Please mark my respsone as helpful/correct, if it answer your question.

Thanks