
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 02:08 AM
Hi Community,
I'd really appreciate some help with a fix script to meet the following requirement:
-> we are removing some custom fields from a form and we don't want to lose the data within them; the ask is to concatenate the data from 2 fields or more into 1 (the one who will be left on the form) without loosing any pre-existent values from the latter (the field where data gets merged)
-> in most cases I will need to merge/concatenate data from 2 string fields but will also have the scenario where I need to concatenate value from string to journal input field type
I've had a few attempts, but with no success:
var gr = new GlideRecord('risk');
gr.query();
while (gr.next()) {
if (gr.get())
current.work_notes = gr.description + gr.mitigation;
}
var gr = new GlideRecord('risk');
gr.query();
while (gr.next()) {
current.work_notes = gr.description + gr.mitigation;
gr.update();
}
var gr = new GlideRecord('risk');
gr.query();
while (gr.next()) {
var field1 = 'description';
var field2 = 'mitigation';
var field3; {
field3 = field1 + field2;
}
current.work_notes = field3;
}
Thank you.
Paula
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 02:20 AM
For
-> we are removing some custom fields from a form and we don't want to lose the data within them; the ask is to concatenate the data from 2 fields or more into 1 (the one who will be left on the form) without loosing any pre-existent values from the latter (the field where data gets merged)
var gr = new GlideRecord('risk');
gr.query();
while (gr.next()) {
gr.work_notes = gr.description + ' ' +gr.mitigation;
gr.update();
}
-> in most cases I will need to merge/concatenate data from 2 string fields but will also have the scenario where I need to concatenate value from string to journal input field type
var gr = new GlideRecord('risk');
gr.query();
while (gr.next()) {
gr.work_notes = gr.description + ' ' +gr.mitigation.getJournalEntry(-1); //suppose gr.mitigation is a journal entry field
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 02:20 AM
For
-> we are removing some custom fields from a form and we don't want to lose the data within them; the ask is to concatenate the data from 2 fields or more into 1 (the one who will be left on the form) without loosing any pre-existent values from the latter (the field where data gets merged)
var gr = new GlideRecord('risk');
gr.query();
while (gr.next()) {
gr.work_notes = gr.description + ' ' +gr.mitigation;
gr.update();
}
-> in most cases I will need to merge/concatenate data from 2 string fields but will also have the scenario where I need to concatenate value from string to journal input field type
var gr = new GlideRecord('risk');
gr.query();
while (gr.next()) {
gr.work_notes = gr.description + ' ' +gr.mitigation.getJournalEntry(-1); //suppose gr.mitigation is a journal entry field
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 03:25 AM
Thank you
May I ask 2 things?
-> what does (-1) mean from get.JournalEntry bit? keen to understand the logic of it so I can apply it forward.
-> how can I avoid these type of entries, basically when one of the field is empty. I can see there is no impact when both fields that need data merge are string type but in the case of one being Journal Input, it still creates an entry.
Tried these but could not save the first one and the 2nd didn't work either when trying to run it:
var gr = new GlideRecord('risk');
gr.query();
while (gr.next()) {
if !current.description.nil() {
gr.work_notes = gr.description + ' ' + gr.work_notes.getJournalEntry(-1);
gr.update();
} else {
return;
}
}
var gr = new GlideRecord('risk');
gr.query();
while (gr.next()) {
gr.addEncodedQuery('descriptionISNOTEMPTY'); {
gr.work_notes = gr.description + ' ' + gr.work_notes.getJournalEntry(-1);
gr.update();
}
}
Thank you again!! 🙂