Help with Fix Script: merge/concatenate data from 2 fields (string to string & string to journal input)

PaulaaO
Mega Sage

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

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

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();
}

 

View solution in original post

2 REPLIES 2

Jaspal Singh
Mega Patron
Mega Patron

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();
}

 

Thank you @Jaspal Singh the scripts are very helpful. Just tried them now and they work.

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.

find_real_file.png

find_real_file.png

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!! 🙂