- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 02:48 AM
Hi,
I need to replace g_form.getReference() by Glide Ajax for the below code , how do i do that.?
Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//Label Value & Field Value
var requestedforLabel = $('label.sc_request.requested_for');
var requestedforField = $('sys_display.sc_request.requested_for');
if (!requestedforLabel || !requestedforField)
return;
if (!newValue) {
requestedforLabel.setStyle({backgroundImage: ""});
requestedforField.setStyle({color: ""});
return;
}
g_form.getReference('requested_for', vipRequestedforCallback); // need to replace this function
}
//callback function
function vipRequestedforCallback(Requestedfor) {
var requestedforLabel = $('label.sc_request.requested_for').down('label');
var requestedforField = g_form.getElement('sys_display.sc_request.requested_for');
if (!requestedforLabel || !requestedforField)
return;
//checking for VIP Status
if (Requestedfor.vip == 'true') {
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "5% 45%";
//highlighting the field
g_form.showFieldMsg('requested_for',"VIP Special Handling",'info');
requestedforLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
requestedforField.setStyle({color:"red"});
}
else {
//removing special handler
requestedforLabel.setStyle({backgroundImage: ""});
requestedforField.setStyle({color: ""});
}
}
Thanks ,
brunda
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 03:07 AM
Create Script include which is client callable
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function(){
var id = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
return gr.vip.toString();
}
},
type: 'checkRecords'
});
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//Label Value & Field Value
var requestedforLabel = $('label.sc_request.requested_for');
var requestedforField = $('sys_display.sc_request.requested_for');
if (!requestedforLabel || !requestedforField)
return;
if (!newValue) {
requestedforLabel.setStyle({backgroundImage: ""});
requestedforField.setStyle({color: ""});
return;
}
// need to replace this function
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_form.getValue('requested_for'));
ga.getXMLAnswer(function(answer){
var requestedforLabel = $('label.sc_request.requested_for').down('label');
var requestedforField = g_form.getElement('sys_display.sc_request.requested_for');
if (!requestedforLabel || !requestedforField)
return;
//checking for VIP Status
if (answer == 'true') {
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "5% 45%";
//highlighting the field
g_form.showFieldMsg('requested_for',"VIP Special Handling",'info');
requestedforLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
requestedforField.setStyle({color:"red"});
}
else {
//removing special handler
requestedforLabel.setStyle({backgroundImage: ""});
requestedforField.setStyle({color: ""});
}
});
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 03:02 AM
Is that a OOB client script.
if yes then why to update that?
So did you start on the GlideAjax? where are you stuck?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 03:07 AM
Create Script include which is client callable
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function(){
var id = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
return gr.vip.toString();
}
},
type: 'checkRecords'
});
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//Label Value & Field Value
var requestedforLabel = $('label.sc_request.requested_for');
var requestedforField = $('sys_display.sc_request.requested_for');
if (!requestedforLabel || !requestedforField)
return;
if (!newValue) {
requestedforLabel.setStyle({backgroundImage: ""});
requestedforField.setStyle({color: ""});
return;
}
// need to replace this function
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_form.getValue('requested_for'));
ga.getXMLAnswer(function(answer){
var requestedforLabel = $('label.sc_request.requested_for').down('label');
var requestedforField = g_form.getElement('sys_display.sc_request.requested_for');
if (!requestedforLabel || !requestedforField)
return;
//checking for VIP Status
if (answer == 'true') {
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "5% 45%";
//highlighting the field
g_form.showFieldMsg('requested_for',"VIP Special Handling",'info');
requestedforLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
requestedforField.setStyle({color:"red"});
}
else {
//removing special handler
requestedforLabel.setStyle({backgroundImage: ""});
requestedforField.setStyle({color: ""});
}
});
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader