ui Action

ashaki
Kilo Expert

I created a UI Action to create a record from an incident and it works well. However, i would like to restrict the ui action from creating a record unless saved. I need help with a script that will only create the record by saving not loading. here is the script i used to create the ui.

var pla = new GlideRecord("u_incidents");

//pla.short_description = current.short_description;

pla.company = current.company;

pla.cmdb_ci = current.cmdb_ci;

pla.priority = current.priority;

pla.parent = current.sys_id;

var sysID = pla.insert();

//current.pla_id = sysID;

var mySysID = current.update();

gs.addInfoMessage("Incident " + pla.number + " to be created");

action.setRedirectURL(pla);

action.setReturnURL(current);

4 REPLIES 4

Subhajit1
Giga Guru

Your pla.insert() is saving the Record on to the Database, Lose that.



var pla = new GlideRecord("u_incidents");


pla.initialize(); // Add this line to your Code


Bhavesh Jain1
Giga Guru

Do not write any query to do this.


Use below code:


Open a Form with Preset Values


Navigating by URL - ServiceNow Wiki


solutioningnow
Giga Guru

Hi,



If you want your button to be visible only on Saved records, you need to uncheck "Show Insert" checkbox.



Please mark answer as correct/helpful if it was really helpful



Regards,


Solutioner


Logo.png


Enhance Knowledge NOW@ www.solutioningnow.com


http://www.solutioningnow.com/


Bhavesh Jain1
Giga Guru

Use below script in your UI action.



action.setRedirectURL('/nav_to.do?uri=incident.do?sys_id=-1%26sysparm_query=priority=1^incident_state=3^caller_id=javascript:gs.getUserID()');


action.setReturnURL(current);




Capture.PNG