- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2015 09:46 PM
For example: I would like to test for the 'Apply Proposed Changes' Button on the Change form when the status changes.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2015 08:30 AM
Here is an old function I use to hide buttons for approval resets.
You could use something like this (create it as an onLoad Client script) and your onLoad calls the function as well as setting it.
Then create an onChange Client script that calls the same routine when something triggers the change to a field / status.
function resetRequestApproval() {
var refs = document.getElementsByTagName("BUTTON");
if (g_form.getValue('approval') == 'not requested')
{
// hide both "Request Reset" and "Reset Approval buttons"
if (refs) {
for (i=0; i < refs.length; i++)
{
ref = refs[i];
buttonphrase = ref.innerHTML;
if (buttonphrase == '<span>Request Reset</span>')
ref.style.display = 'none';
if (buttonphrase == '<span>Reset Approval</span>')
ref.style.display = 'none';
}
}
}
else
{
// Hide Reset Approval and show Request Reset
if (refs) {
for (i=0; i < refs.length; i++)
{
ref = refs[i];
buttonphrase = ref.innerHTML;
if (buttonphrase == '<span>Request Reset</span>')
ref.style.display = '';
if (buttonphrase == '<span>Reset Approval</span>')
ref.style.display = 'none';
}
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2015 11:38 PM
Hi Peter, If u want to check the condition for the button..y dont u use ui action ?
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2015 03:07 AM
H Peter,
are you meaning that you would like to have a conditional button? i.e. the button should you when the status changes to a particular status?
You could look at UI Policies:
Creating a UI Policy - ServiceNow Wiki
and at the UI Actions (editing and creating):
Not sure if this blog could be of help:
Let me know if you need more help.
Kind regards,
Alexandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2015 06:53 AM
Are you looking for something like the below
var action = g_form.getActionName();
It returns the name of the action on button click.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2015 07:06 AM
there's a method I've used before to change the colour of a button which checks to see if the button is there, you need to find out the 'action_name' of the button and then swap, buttonID for your action_name value:
try{ //Find the button(s) by ID and change the background color $$('button[id=' + buttonID + ']').each(function(elmt) { elmt.style.backgroundColor = backgroundColor; }); }catch(e){} | |
the reason I used that example is so you can see there is a way to check if the button exists, so you can return true rather than change the background
EDIT: I remember where I get this from now, the SNGURU site: http://www.servicenowguru.com/scripting/client-scripts-scripting/change-form-button-color/