- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:33 AM
Hi all,
I have created one record, in a record Producer I have created one variable requested for, I want to make the requested for read only when requested for user belongs to only one location. Can someone please help me? and i want this requirement to be achieved by using script include. please provide as early as possible.
Thanks and Regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 03:17 AM
Hello @SNOW24 ,
You have to use a script include and an onchnage client script as below:
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('asu_GetLocationData');
ga.addParam('sysparm_name', 'getlocation');
ga.addParam('sysparm_user', g_form.getValue("requested_for"));
ga.getXMLAnswer(updateCampus);
}
function updateCampus(answer) {
var clearvalue;
if (answer == 'true'){
g_form.setReadOnly('requested_for',true);
}
else {
g_form.setReadOnly('requested_for',false);
}
}
Script include:
var asu_GetLocationData = Class.create();
asu_GetLocationData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getlocation: function () {
var user = this.getParameter('sysparm_user');
var loc = new GlideRecord('sys_user');
loc.addQuery('sys_id',user);
loc.addQuery('location','your location sys_id');
if (loc.next()) {
return 'true';
}
else {
return 'false';
}
});
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:54 AM
Hello @SNOW24
var gr = new GlideRecord("sys_user");
var count =0;
gr.query();
while(gr.next()) {
if (gr.location) {
count++;
}
}
if(count==1){
return true;
}
Use Client Script and check if true is coming from script include,
Make it readonly.
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 03:17 AM
Hello @SNOW24 ,
You have to use a script include and an onchnage client script as below:
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('asu_GetLocationData');
ga.addParam('sysparm_name', 'getlocation');
ga.addParam('sysparm_user', g_form.getValue("requested_for"));
ga.getXMLAnswer(updateCampus);
}
function updateCampus(answer) {
var clearvalue;
if (answer == 'true'){
g_form.setReadOnly('requested_for',true);
}
else {
g_form.setReadOnly('requested_for',false);
}
}
Script include:
var asu_GetLocationData = Class.create();
asu_GetLocationData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getlocation: function () {
var user = this.getParameter('sysparm_user');
var loc = new GlideRecord('sys_user');
loc.addQuery('sys_id',user);
loc.addQuery('location','your location sys_id');
if (loc.next()) {
return 'true';
}
else {
return 'false';
}
});
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 03:49 AM
Hello @SNOW24 ,
if my answer helped you please mark it as correct.
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.