- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2017 02:46 AM
I have created a UI action Locked. I want when user click on it , it should be grayed out . Screenshot attached (UI Action encircled in red) :-
Thanks,
Saurabh
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2017 02:44 AM
Hi Sourav,
Here you go. The below procedure works for me
1. Create a custom checkbox on your form(for me its flag)
2. Write the below code on the locked out UI action
function hello()
{
document.getElementById("159c99bb4f303200b5d50ab18110c747").disabled = true;
var ga = new GlideAjax("hello");
ga.addParam("sysparm_name","hello2");
ga.addParam("sysparm_parent",g_form.getValue('number'));
ga.getXML(test2);
function test2(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
}
}
3. And the script include
var hello = Class.create();
hello.prototype = Object.extendsObject(AbstractAjaxProcessor, {
hello2: function() {
var groupID=this.getParameter('sysparm_parent');
gs.log('testing1'+groupID);
var gr=new GlideRecord("incident");
gr.addQuery('number',groupID);
gr.query();
if(gr.next())
{
gr.u_flag='true';
gr.update();
}
},
type: 'hello'
});
4. To control the reloading issue, write the below onload client script
function onLoad() {
//Type appropriate comment here, and begin script below
if(g_form.getValue('u_flag')=='true')
{
document.getElementById("159c99bb4f303200b5d50ab18110c747").disabled = true;
}
}
Please note: I haven't used the try/catch statements, but you need to use it in your code while playing with DOM.
Also you need to hide the flag button from the form through UI policy or ACL(dont remove it from form layout or else it will not work).
Please hit LIKE or mark HELPFUL if found appropriate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2017 08:36 AM
Yes, just a flag like a custom field(a check box) just to check if the button is clicked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2017 09:45 AM
I am not able to do this. Could you please give me an example for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2017 07:56 PM
Can anyone let me know how can I restrict that on reload form UI action remain and fields remain grayed out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2017 02:42 AM
Hi Sourav,
Here you go. The below procedure works for me
1. Create a custom checkbox on your form(for me its flag)
2. Write the below code on the locked out UI action
function hello()
{
document.getElementById("159c99bb4f303200b5d50ab18110c747").disabled = true;
var ga = new GlideAjax("hello");
ga.addParam("sysparm_name","hello2");
ga.addParam("sysparm_parent",g_form.getValue('number'));
ga.getXML(test2);
function test2(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
}
}
3. And the script include
var hello = Class.create();
hello.prototype = Object.extendsObject(AbstractAjaxProcessor, {
hello2: function() {
var groupID=this.getParameter('sysparm_parent');
gs.log('testing1'+groupID);
var gr=new GlideRecord("incident");
gr.addQuery('number',groupID);
gr.query();
if(gr.next())
{
gr.u_flag='true';
gr.update();
}
},
type: 'hello'
});
4. To control the reloading issue, write the below onload client script
function onLoad() {
//Type appropriate comment here, and begin script below
if(g_form.getValue('u_flag')=='true')
{
document.getElementById("159c99bb4f303200b5d50ab18110c747").disabled = true;
}
}
Please note: I haven't used the try/catch statements, but you need to use it in your code while playing with DOM.
Also you need to hide the flag button from the form through UI policy or ACL(dont remove it from form layout or else it will not work).
Please hit LIKE or mark HELPFUL if found appropriate

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2017 08:39 PM
You are trying to enforce Business Logic via the Presentation layer (client side).
There are a few issues with this approach:
- Takes more time to implement
- Is difficult to test
- Can be easily bypassed by a crafty end user (via DOM manipulation)
- Is not supported by the vendor
- Will not work in Service Portal
- Will probably break in the next platform UI change, which may also stop other client side code from running
This should be done via ACL's and State (server side) as suggested by davidsmith
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022