location field in sc_task table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2024 01:52 AM
Hello,
Can someone shed some light on how the Location field in the sc_task table gets populated? Where should I set the value for the Location field so that it populates correctly in the sc_task table?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2024 09:31 AM
Hi @bondita1 ,
Create client script and script include.
Script include:
Name: PopulateLocationField
Client Callable: Yes
Script:
var PopulateLocationField = Class.create();
PopulateLocationField.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUsersValues : function()
{
//var callerID = this.getParameter('sysparm_requested_for');
var callerId=" ";
var req_item=this.getParameter('sysparm_req_item');
var gr_req_item= new GlideRecord("sc_req_item");
gr_req_item.addQuery("sys_id",req_item);
gr_req_item.query();
if(gr_req_item.next())
{
callerId= gr_req_item.request.requested_for;
}
gs.log("callerid"+ callerId);
var location=" ";
//get user record:
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',callerId);
gr.query();
if (gr.next()){
location = gr.location;
}
return location;
},
type: 'PopulateLocationField'
}
);
Client Script:
Name: Populate_Location_ManualTask
Type: onLoad
Table: sc_task
Global: Yes
UI Type: Desktop
Script:
function onLoad() {
if(g_form.getValue('location')==''|| g_form.isNewRecord())
{
try{
var request_item=g_form.getValue("request_item");
//alert("req_item"+request_item);
var gajax = new GlideAjax('PopulateLocationField');
gajax.addParam('sysparm_name', 'getUsersValues');
gajax.addParam('sysparm_req_item', request_item);
gajax.getXML(ajaxResponse);
function ajaxResponse(xml) {
var answer = xml.responseXML.documentElement.getAttribute("answer");
// alert("answer"+ g_form.getValue("location"));
g_form.setValue("location", answer);
g_form.save();
}
} catch(e){}
}}
Approach 2:
This business rule will need to be created on the sc_req table, as the requested for field will be changing there when changed on the sc_task dot walked field.
(function executeRule(current, previous /*null when async*/) {
var userChange = current.requested_for.location;
var requestSysid = current.getUniqueValue();
var scTaskRecord = new GlideRecord('sc_task');
scTaskRecord.addQuery('request', requestSysid);
scTaskRecord.query();
while(scTaskRecord.next()){
scTaskRecord.location = userChange;
scTaskRecord.update();
}
})(current, previous);