Script include to query a record and set the value of specific field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 12:39 AM
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:
Please help with the code
Thanks,
Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 03:22 AM
Well, I am not sure about the configuration of your Action/Button. But below is the script include and client script function.
Script Include
var UpdateApprovalRecords = Class.create();
UpdateApprovalRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
updateApprovals: function() {
var msg = 'No record found to be updated.';
var grApproval = new GlideRecord('sysapproval_approver');
grApproval.addQuery('<backend_name_of_field_approval_type>', '<backend_value_of_parallel_choice>');
grApproval.query();
if (grApproval.hasNext()) {
msg = 'Some records have been updated.';
while (grApproval.next()) {
grApproval.setValue('<backend_name_of_field_parallel_approvals_initiated', true);
grApproval.update();
}
}
return msg;
},
type: 'UpdateApprovalRecords'
});
Your script include must be in your Application Scope and API name of your script include will be prefixed with application scope. See the below image for reference.
Client Script Function
function onClick() {
var ga = new GlideAjax('global.UpdateApprovalRecords'); // Make sure to use API name of your Script Include here.
ga.addParam('sysparm_name', 'updateApprovals');
ga.getXML(callBack);
function callBack(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
alert(answer);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 04:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 05:26 AM
Try writing client script outside the onClick() function (means remove the onClick() function but keep the script which is inside of it).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 05:40 AM
Hi,
Still no luck!
Please help on this!
Thanks,
Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 06:06 AM
Hi Muhammad,
Its partially working, if i try below code:
script include:
client script:
But this is updating all my records which is of parallel type.
I just need to restrict to my sctask, from where i'm intiating this.
Please suggest and help with the modification.
Thanks,
Sri