Can someone help with the condition and script for creating an incident with UI Action?

Dlam
Tera Expert

I am trying to create a UI Action for an incident to be created when a contract substate is aborted.

I am very new to script and UI action is not covered in the SNAF course. It will be much appreciated if anyone could help out. 

I have tried to create a UI Action below but it does not work.

Show insert YES

Show update YES

Application GLOBAL

Form context menu YES

Condition: (substate=='Aborted') && gs.hasRole("contract_manager")

Script:

createIncident();
function createIncident() {
    var newIncident = new GlideRecord('incident');
    newIncident.initialize();
    newIncident.short_description = 'New incident recorded at '+gs.nowDateTime();
newIncident.setDisplayValue('caller_id','Abby.Lincoln');
    var sys_id = newIncident.insert();   
action.setRedirectURL(newIncident);
}

Dlam_0-1693486136557.png

 

 

1 ACCEPTED SOLUTION

Hi Dlam, you need to include current. before substate.

 

Also, make sure you're checking for the value of the substate, not the label.  The value is probably 'aborted' in lower case (I don't have 'Aborted' as an option in my list, so I assume it's either part of something I don't have installed, or a customisation, either way, I can't check it to be sure.)

 

That would mean your condition should be:

   current.substate == 'aborted' && gs.hasRole("contract_manager")

View solution in original post

14 REPLIES 14

Yes, with the original script, the new incident form does have the mandatory fields populated, which are the caller and short description.

Will you be able to help with the condition for the UI Action? The button also appears when the substate is not Aborted:

Dlam_1-1693542452585.png

 

Hi Dlam, you need to include current. before substate.

 

Also, make sure you're checking for the value of the substate, not the label.  The value is probably 'aborted' in lower case (I don't have 'Aborted' as an option in my list, so I assume it's either part of something I don't have installed, or a customisation, either way, I can't check it to be sure.)

 

That would mean your condition should be:

   current.substate == 'aborted' && gs.hasRole("contract_manager")

Agreed with Berin.
Also, your UI action is a Form Context menu, which will be shown when someone right click the header in a form within that ast_contract table and manually choose your UI action.

 

A business rule (server side script) would be the best choice.

Dlam
Tera Expert

Thanks all for your help.

The workaround for now is to use my initial script to create a form button. I also created a Template of incident form so the user can click on the button on the form and choose the template to create an incident.

I will be exploring how to set a business rule to automate the incident to be created once the substate == aborted. Any suggestion will be appreciated as always.

Cheers.

Dlam
Tera Expert

Thanks you Berin. It worked!

I did test adding "current." before substate earlier, while the form button did not appear so I thought it was the wrong value but did not realise the choice is 'aborted' instead of 'Aborted'.

Have a great weekend.