Current object has new record values when current.insert() fails

santhoshaitha
Kilo Expert

Hello All,

We have a UI action which creates a new Record by copying the content from existing record.

Below is the similar code:

var obj = current.insert();

{

//some code which does updates on the object 'obj'

}

action.setRedirectURL(current);

The 'current.insert()' is failing because of a before insert Business Rule failure on the table (of which the 'current' belongs to). ,The Business Rule check is working fine and even the UI action abort also working fine. The main issue is that after it redirect to the 'current', it has the values of the new record in the form instead of existing values.

Say suppose the 'Number' of the current is 'TASK0001', after redirection it shows the number of the 'current' as 'TASK0089' which is the next number in the counter sequence.

Can someone please explain which is this? Is something wrong in the code or the UI Action configuration?

Thanks and Regards,
Santhosh

1 ACCEPTED SOLUTION

srinivasthelu
Tera Guru

Hi Santhosh,



That is the expected behavior. UI Action looks fine.




Thanks


Srini


View solution in original post

7 REPLIES 7

srinivasthelu
Tera Guru

Hi Santhosh,



That is the expected behavior. UI Action looks fine.




Thanks


Srini


Ravi Prasad1
Tera Guru

Can you please paste all the UI action code here ?



You should use current.insert();   after mapping all the values.


Hi Ravi,



Below is the exact script in the UI Action:


-----------------------------------------


current.u_initiator = '';


current.assigned_to = '';


current.u_requested_imp_date = '';


current.u_impl__date = '';


current.follow_up = '';


current.u_ambition = '';


current.u_line_items = '';


current.u_line_items_connected = '';


current.u_controlling_ambition = '';


var copypcc = current.insert();




if(current.u_split == true)


{


var pcc = new splitorcopyorcreatePCCSTRAIM();


pcc.createProblem(copypcc);


}



action.setRedirectURL(current);



---------------------------------------



Thanks and Regards,


Santhosh


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Santosh,



Current is a global object OOB that refers to the record you're on, so that would be the existing record in your ui action. You would need to use GlideRecord to create an additional record. Could you post your ui action code?