Copying Field Within UI Action

JW22
Tera Contributor

Hello All,

 

Does anyone know if it's possible to copy and insert a field's value into another field within a UI Action? For example, in the following script, I'd like to copy the current incident number and input it into the field "Original Incident Number", within the new incident that is being created. Essentially this UI Action will enable our users to duplicate incidents but we want to keep track of the original incident number on the new incident for reference.

 

The UI Action runs as expected and creates the new incident record, but the "Original Incident Number" (which is a reference field), is still empty. 

 

if (typeof current.number != 'undefined' && current.number) {
    current.state = 1; 
    current.comments = "Incident duplicated from " + current.number
    current.number = ""; // Generate a new incident number

if (current.u_original_incident_number.isNil())
current.u_original_incident_number = current.number;

current.insert();
action.setRedirectURL(current);

}

 

Thank you!

 

1 ACCEPTED SOLUTION

DYCM
Mega Sage

Hi @JW22 ,

after changing 

current.u_original_incident_number = current.number

to 

current.u_original_incident_number = current.sys_id.toString();

u_original_incident_number field will be populated with value. 

I tested in my PDI, please check the screenshots below:

1.png2.png

3.png

4.png

View solution in original post

5 REPLIES 5

Bert_c1
Kilo Patron

Hi,

try changing your line to

 

current.u_original_incident_number = current.sys_id.toString();

 

since the 'u_original_incident_number' field is a Reference field.

JW22
Tera Contributor

Thanks for your help! Unfortunately no luck with that change, the 'Original Incident Number' field is still empty on the new incident that is created from the UI Action. 

Bert_c1
Kilo Patron

There is several OOB 'Create Incident' UI Actions. Refer to those as examples.

DYCM
Mega Sage

Hi @JW22 ,

after changing 

current.u_original_incident_number = current.number

to 

current.u_original_incident_number = current.sys_id.toString();

u_original_incident_number field will be populated with value. 

I tested in my PDI, please check the screenshots below:

1.png2.png

3.png

4.png