get last work notes in client script

DoDo labs___
Mega Sage

Hello,

 

What is wrong with the below client script? 

The sys_id shows up correctly, but nothing else appears.

 

Table: Change Request

Type: onLoad

 

function onLoad() {
 
    var sysid = g_form.getUniqueValue();
 
    alert(sysid);
 
var x = new GlideRecord('sys_journal_field');
    x.addQuery('element_id',sysid);
    x.addQuery('element','comments');
    x.query();
    if(x.next())
        {
            alert(x.name);
        }
   
}
1 ACCEPTED SOLUTION

Karan Chhabra6
Mega Sage

HI @DoDo labs___ ,

 

You should be writing this server side script either in script include or business rule, for this requirement you can create a display business rule and use g_scratchpad to send the latest work notes to client side and then display it as alert, please follow these steps:

 

Step 1: create a display business rule on change_request table

KaranChhabra6_0-1684863666352.png

KaranChhabra6_2-1684863948796.png

 

Use this script:

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

	g_scratchpad.workNotes = current.work_notes.getJournalEntry(1);

})(current, previous);

 

Step 2: Update your client script and make these changes:

 

function onLoad() {

alert(g_scratchpad.workNotes);

}

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

 

View solution in original post

5 REPLIES 5

Rahul Kumar17
Tera Guru

Hi,

function onLoad() {
    var sysid = g_form.getUniqueValue();
    alert(sysid);

    var x = new GlideRecord('sys_journal_field');
    x.addQuery('element_id', sysid);
    x.addQuery('element', 'comments');
    x.query();
    if (x.next()) {
        var fieldName = x.getValue('element');
        alert(fieldName);
    }
}

 

Thanks,

Rahul Kumar

 

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

But based on that you can use Script include

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

Thanks for your quick reply, but still no work notes showing up 😞

Karan Chhabra6
Mega Sage

HI @DoDo labs___ ,

 

You should be writing this server side script either in script include or business rule, for this requirement you can create a display business rule and use g_scratchpad to send the latest work notes to client side and then display it as alert, please follow these steps:

 

Step 1: create a display business rule on change_request table

KaranChhabra6_0-1684863666352.png

KaranChhabra6_2-1684863948796.png

 

Use this script:

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

	g_scratchpad.workNotes = current.work_notes.getJournalEntry(1);

})(current, previous);

 

Step 2: Update your client script and make these changes:

 

function onLoad() {

alert(g_scratchpad.workNotes);

}

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!