Sync work notes Project and Demand

Farfara
Tera Contributor

Hello everyone,

 

I would like to copy work notes from demand to project. 

Can you help on this topic.

 

I created a before BR :

Table : dmn_demand

 

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

var gr = new GlideRecord('pm_project');
gr.addQuery('demand', current.sys_id);

gr.query();
while (gr.next()) {
    if(gr.comments.getJournalEntry(1).indexOf(current.comments) == -1 && gr.work_notes.getJournalEntry(1).indexOf(current.work_notes) == -1) {
        gr.work_notes = current.work_notes;
        gr.comments = current.comments;
        gr.update();

    }

}
})(current, previous);

 

 

Farfara_0-1688120759124.png

 

FF

1 ACCEPTED SOLUTION

Manmohan K
Tera Sage

Hi @Farfara 

 

You should be retrieving the latest value for work notes and comments in current record too

Test with below code

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

    var gr = new GlideRecord('pm_project');
    gr.addQuery('demand', current.sys_id);

    gr.query();
    while (gr.next()) {

        if (gr.comments.getJournalEntry(1).indexOf(current.comment.getJournalEntry(1)) == -1 && gr.work_notes.getJournalEntry(1).indexOf(current.work_notes.getJournalEntry(1)) == -1) {

            gr.work_notes = current.work_notes.getJournalEntry(1);
            gr.comments = current.comments.getJournalEntry(1);
            gr.update();

        }

    }
})(current, previous);

 

View solution in original post

2 REPLIES 2

Manmohan K
Tera Sage

Hi @Farfara 

 

You should be retrieving the latest value for work notes and comments in current record too

Test with below code

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

    var gr = new GlideRecord('pm_project');
    gr.addQuery('demand', current.sys_id);

    gr.query();
    while (gr.next()) {

        if (gr.comments.getJournalEntry(1).indexOf(current.comment.getJournalEntry(1)) == -1 && gr.work_notes.getJournalEntry(1).indexOf(current.work_notes.getJournalEntry(1)) == -1) {

            gr.work_notes = current.work_notes.getJournalEntry(1);
            gr.comments = current.comments.getJournalEntry(1);
            gr.update();

        }

    }
})(current, previous);

 

Voona Rohila
Kilo Patron
Kilo Patron

Hi @Farfara 

Can you explain in detail of your requirement?

This works : 

 

(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('pm_project');
gr.addQuery('demand', current.sys_id);
gr.query();
while (gr.next()) {
        gr.work_notes = current.work_notes;
        gr.comments = current.comments;
        gr.update();
}
})(current, previous);

 

Are you are syncing up from demand to project and vice versa too? Refer below link - https://www.servicenow.com/community/now-platform-articles/copy-task-comments-and-worknotes-to-paren...

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP