Map variable to different table

rajasekar reddy
Tera Contributor

Hi experts,

we have created variables called 'firstname', 'last name' & 'middle name' in a variable set of a record producer.

Our record producer creates a record in incident table.  We have custom fields 'firstname', 'last name' & 'middle name' on Incident table and guest table (custom table).

My requirement is when record producer is submitted, we need to update 'firstname', 'last name' & 'middle name' both in incident and guest tables.

For incident, I have mapped the fields and it is working fine. But how can I update custom table fields.

 

Can someone help.  TIA

 

1 ACCEPTED SOLUTION

@rajasekar reddy it need not be any field because second line is to filter the records that you want to update .

Lets say if you want to update a particular record with active as true so you can write like 

 

var gr = new GlideRecord('your_custom_table');
gr.addQuery('active',true);
gr.query();
if(gr.next())
{
gr.your_first_name_field_backend_name = producer.your_first_name_variable_backend_name;
gr.your_last_name_field_backend_name = producer.your_last_name_variable_backend_name;
gr.your_middle_name_field_backend_name = producer.your_middle_name_variable_backend_name;
gr.update();
}

Like this as per your requirement if you have any particular records  to be updated in your custom table then build a query accordingly just like the above .

 

Mark the answer correct if this helps you

View solution in original post

6 REPLIES 6

Mike_R
Kilo Patron
Kilo Patron

If you are trying to insert a new record into the guest table, use this in your record producer script.

 

var gr = new GlideRecord('guestTableName'); // set your table name
gr.initialize();
gr.firstNameFieldName = producer.variableNameForFirst; // update with the correct variable & column names
gr.lastNameFieldName = producer.variableNameForLast; // update with the correct variable & column names
gr.middleNameFieldName = producer.variableNameForMiddle; // update with the correct variable & column names
gr.insert();

Mohith Devatte
Tera Sage
Tera Sage

hello @rajasekar reddy ,

You can use record producer script by gliding your custom table and updating your record like below.

Write this below script in record producer script field 

 

var gr = new GlideRecord('your_custom_table');
gr.addQuery('your_field_name','value');
gr.query();
if(gr.next())
{
gr.your_first_name_field_backend_name = producer.your_first_name_variable_backend_name;
gr.your_last_name_field_backend_name = producer.your_last_name_variable_backend_name;
gr.your_middle_name_field_backend_name = producer.your_middle_name_variable_backend_name;
gr.update();
}

 

Hope this helps 

Mark the answer correct if this helps you in any way 

Thanks

rajasekar reddy
Tera Contributor

Hey Mohith, what should be the field name and value in second line of script. I need to update only 3fields from 3 varibles

@rajasekar reddy it need not be any field because second line is to filter the records that you want to update .

Lets say if you want to update a particular record with active as true so you can write like 

 

var gr = new GlideRecord('your_custom_table');
gr.addQuery('active',true);
gr.query();
if(gr.next())
{
gr.your_first_name_field_backend_name = producer.your_first_name_variable_backend_name;
gr.your_last_name_field_backend_name = producer.your_last_name_variable_backend_name;
gr.your_middle_name_field_backend_name = producer.your_middle_name_variable_backend_name;
gr.update();
}

Like this as per your requirement if you have any particular records  to be updated in your custom table then build a query accordingly just like the above .

 

Mark the answer correct if this helps you