Onclick UI action should be grayed out

coolsaurabh
Tera Contributor

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) :-

Qt.jpg

Thanks,

Saurabh

1 ACCEPTED SOLUTION

ark6
Mega Guru

Hi Sourav,



Here you go. The below procedure works for me



1. Create a custom checkbox on your form(for me its flag)


find_real_file.png



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");


}


  }


find_real_file.png



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'


});



find_real_file.png



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


View solution in original post

27 REPLIES 27

I believe his actual requirement is to disable a button when its clicked. As there are no defined functions in SNOW to disable a button, he may need to try a DOM manipulation with a try/catch statement so that in further upgrade if there is a change in id of the element, the other functionalities will not stop and he can proceed with his requirement


Jack
Tera Guru

If I understand your requirement: When user click this button => set read-only for some fields in this form.


This is my suggestion:


1) Define a hidden field (type=True/False)


example: u_editable (default = true)


2) When User click this button => set hidden field u_editable = false


3) Create an UI Policy with:


Apply: u_editable = false


Actions: Add list fields that you want to set read-only.


find_real_file.png


If another user opens the record, the 'u_editable' flag value won't have been saved in the DB, so the record won't be locked, defeating the purpose of the requirement.


It really needs to be implemented via ACL and UI action submission.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

You right.


I misunderstood his requirement.


Dave Smith1
ServiceNow Employee
ServiceNow Employee

Jack Lu wrote:



I misunderstood his requirement.


To be fair, the original requirement was about disabling a button upon click.



Later, additional requirements emerged: disabling specific fields when the button is clicked, persisting this action rather than remain a client-side action, so the solution initially presented fulfilled what was asked for... but not what was actually needed.   This is a good example of having a clear problem definition and describing desired outcomes, rather than the journey to get there.



I asked for clarification earlier here: Re: Onclick UI action should be grayed out   but received no response, other than later suggestions actually following my proposed design, so my guess should hopefully steer the original poster back on track.