how we get 1. Create a record in Table2 whenever a record is inserted into Table1. 2. Update Short Description of a particular record of Table2 whenever a record is updated in Table1.

sachin dhek
Kilo Contributor

i am a fresher i am stuck in this problem last 3 days 

1 ACCEPTED SOLUTION

You need to add some query if you want to update existing record.

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var gr = new GlideRecord('u_table_1');
gr.addQuery(); // eg. gr.addQuery('fieldName', 'value'); 
//gr.addQuery('active', true);  // eg
gr.query();
//gr.insert();  // use this line if you want to create new record
while(gr.next()){

gs.log(gr.u_table_2); // here use gr.fieldName

gr.fieldName = 'value';
gr.update();  // to update the record matching your query.
 
}

})(current, previous);

 

Note: replace fieldName as per your column/field names in your tables.

 

Thanks,
Anil Lande

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

20 REPLIES 20

Glad it worked for you.

Can you please mark my answer as correct and close this thread for others.

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

hlw sir i need your help for this:-

Create a button called Populate on Incident form clicking on which, the Short Description of that Incident gets prepend with the word “AUTO-TEXT: ”. The button should only be visible once the Incident record is submitted.

Create an action called get sysID in List Context Menu of Incident Table. Clicking this should show an alert with the list of sysIDs of the selected records.

I have made both the buttons  but they are not working

script is:

for get sysID:

function contextMenu() {
var get_sysID = current.getUniqueValue();
alert("sysID of the selected records is = " + get_sysID);
}

 

for populate :

function getShortDescription(){

g_form.setValue('short_description' + 'AUTO TEXT');
}

is this script write or not?

@sachin dhek 

I am a bit confused here. I have given an end to end steps on what you need to do to achieve your requirement and once you confirmed that it is working for you , I asked you to mark my answer as correct which you did and now I see it's been changed.

Did you accidentally marked the other answer as correct?

I also do not see a follow up question related to the one mentioned in the subject of this thread except this as below:

For this will suggest you to open a new thread in community and please review if you have marked the appropriate response as correct or not in this thread for other.

find_real_file.png

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

in this the answer to the question i have asked earlier is correct:  but i am asking you about one more problem, how will i script it?

Create a button called Populate on Incident form clicking on which, the Short Description of that Incident gets prepend with the word “AUTO-TEXT: ”. The button should only be visible once the Incident record is submitted

What if there are multiple child tables? For example, if you select a value from a dropdown, say value 1, a ticket in child table 1 is created. If you select dropdown value 2, a ticket in child table 2 is created, etc.?