g_scratchpad issue

Community Alums
Not applicable

Hi,

 

I know i should have created a Business Rule on Problem Task table but I want to create on Problem table to see why it doesn't work. It didn't work. Keeping it as it is, please tell me what Is wrong so that I can learn and correct myself.

 

1.png

 

2.png

 

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

	var gr = new GlideRecord('problem_task');
	gr.short_description = current.short_description;
	g_scratchpad.SD = gr.short_description;
	gr.assignment_group = current.assignment_group;
	g_scratchpad.AG = gr.assignment_group;
	gr.description = current.description;
	g_scratchpad.Desc = current.description;
})(current, previous);

 

3.png

 

function onLoad() {

	g_form.setValue('short_description', g_scratchpad.SD);
	g_form.setValue('description', g_scratchpad.Desc);
	g_form.setValue('assignment_group', g_scratchpad.AG);

}

 

Regards

Suman P.

7 REPLIES 7

anshul_goyal
Kilo Sage

Hello @Community Alums,

Could you please elaborate more on your requirement? As far as I understand, you want to pass the values of the Problem fields to g_scratchpad and then update them on the Problem Task record.

Let me know if my understanding is correct.


Thanks

Paul Curwen
Giga Sage

Your  GlideRecord is doing nothing on line 3 of your Business Rule. As you are not filtering or querying it in any way, or doing an update of Problem Task etc etc. What are you trying to do there?

 

If you just want to store Problem table fields in scratchpad, then take out all the gr references (lines 3,4,68) for Problem Task and the scratchpad will populate. 


See: GlideRecord Query Cheat Sheet - ServiceNow Guru

 

	var gr = new GlideRecord('problem_task');

This post may also help you understand the issue: 

 

Display Business Rule and g_scratchpad - ServiceNow Community

 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

Community Alums
Not applicable

Hi @Paul Curwen,

 

I corrected it, but it still didn't work.

 

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

    var gr = new GlideRecord('problem_task');
    gr.addQuery(gr.problem, current.sys_id);
    gr.query();
    if (gr.next()) {

        gr.short_description = current.short_description;
        g_scratchpad.SD = gr.short_description;
        gr.assignment_group = current.assignment_group;
        g_scratchpad.AG = gr.assignment_group;
        gr.description = current.description;
        g_scratchpad.Desc = current.description;

    }

})(current, previous);

Juhi Poddar
Kilo Patron

Hello @Community Alums 

Few points for business rules:

  • If you are trying to create a new record in "problem_task" table then gr.insert() is missing
  • g_stratchpad is used to pass data to the client side. You can directly set values from current record
(function executeRule(current, previous /*null when async*/) {
    // Ensure 'g_scratchpad' is populated
    g_scratchpad.SD = current.short_description || '';
    g_scratchpad.AG = current.assignment_group.getDisplayValue() || ''; // Use getDisplayValue() for reference fields
    g_scratchpad.Desc = current.description || '';
})(current, previous);

Client script:

function onLoad() {
    if (g_scratchpad) {
        // Set values from g_scratchpad
        if (g_scratchpad.SD) {
            g_form.setValue('short_description', g_scratchpad.SD);
        }
        if (g_scratchpad.Desc) {
            g_form.setValue('description', g_scratchpad.Desc);
        }
        if (g_scratchpad.AG) {
            g_form.setValue('assignment_group', g_scratchpad.AG);
        }
    }
}

Note: Add logs to see if the data exist.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar