Copy data from one field into another's table work notes using UI action

Nestor Padilla1
Giga Expert

Hi

I need a UI Action that closes the current ticket (incident) and sets a record on another table to a specific state.

Background:

I have this custom app called Lift Intake, this is a form with some predefined profiles that can automatically create Incidents or Requests.

When you create an incident or request from the intake form, the new incident or request will have the Intake Ticket number associated under the Related Records tab, on a field named: "Source Intake Ticket", at the same time the new Incident or Request number will be set under a referenced field named "Target Task" at the Intake Ticket form/table.

I'm trying to create a UI action that will close the current incident (or request, for the purpose of this question I will refer only to incidents), set another record in another table to a specific state (Work in Progress), clear the Target Task field and copy the Resolution Notes from the incident into the work notes on the Intake Ticket.

Everything works except for the copy resolutions notes part.

The UI does close the incident, sets the intake ticket back to work in progress state and clears the target task field, but it does not copy the resolution notes from the incident into the intake ticket work notes.

Here is the UI action code I have created (not a super expert):

function returnIntake(){
var answer=confirm("Are you sure you want Close this Incident and Return it to Intake?");
if (answer==false)
{
return false;
}

g_form.setValue('incident_state', 7);
g_form.setValue('state', 7);
g_form.setValue('close_code', 'Cancelled/duplicate');
//g_form.setValue('close_notes', 'This is a Returned Incident');

gsftSubmit(null, g_form.getFormElement(), 'ReturnButton'); // This is the name of the 'Action Name', this must be called.
}

//Code that runs without 'onclick'
if(typeof window == 'undefined')
serverReturn();

function serverReturn(){
var intakeGR = new GlideRecord("x_fru_lift_commerc_intake");
intakeGR.addQuery('target_task', current.sys_id.toString());
intakeGR.query();
if(intakeGR.next()){
intakeGR.state = "2";
intakeGR.target_task = 'NULL';
intakeGR.work_notes = current.close_notes.toString();
intakeGR.update();
}
current.state = 7;
current.update();
}

Please, if you could provide advice on how to fix this code and also if I could copy the last incident work notes too.

Thanks for your help.

1 ACCEPTED SOLUTION

Rahul RJ
Giga Sage
Giga Sage

Hi,

You can use below code to get close_notes.

intakeGR.work_notes = current.close_notes.getJournalEntry(1);

 

Thanks,

RJ

View solution in original post

4 REPLIES 4

Omkar Mone
Mega Sage

Hi 

Can you try with this once - 

 

function returnIntake(){
var answer=confirm("Are you sure you want Close this Incident and Return it to Intake?");
if (answer==false)
{
return false;
}

g_form.setValue('incident_state', 7);
g_form.setValue('state', 7);
g_form.setValue('close_code', 'Cancelled/duplicate');
//g_form.setValue('close_notes', 'This is a Returned Incident');

gsftSubmit(null, g_form.getFormElement(), 'ReturnButton'); // This is the name of the 'Action Name', this must be called.
}

//Code that runs without 'onclick'
if(typeof window == 'undefined')
serverReturn();

function serverReturn(){
var msg = "Copying Close Notes of Incident";
var intakeGR = new GlideRecord("x_fru_lift_commerc_intake");
intakeGR.addQuery('target_task', current.sys_id.toString());
intakeGR.query();
if(intakeGR.next()){
intakeGR.state = "2";
intakeGR.target_task = 'NULL';
intakeGR.work_notes = msg + ":" +current.close_notes;
intakeGR.update();
}
current.state = 7;
current.update();
}

Let me know if it works.

 

Regards,

Omkar Mone

Rahul RJ
Giga Sage
Giga Sage

Hi,

You can use below code to get close_notes.

intakeGR.work_notes = current.close_notes.getJournalEntry(1);

 

Thanks,

RJ

I tried your suggestion but still didn't work.

Thanks a lot for the time.

Hi,

Thanks a lot, this did the trick.