Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Displaying value into Field using Client Script.

Jeck Manalo
Tera Guru

 

Hi Everyone,

 

I am trying to display the value on stakeholders table that is currently related list into Project. 

 

Which i want to display the value using client script on this below field.

 

Can you check this below code ?

JeckManalo_0-1706243553277.png

 

JeckManalo_1-1706243667988.png

 

 

function onLoad() {

var PO = new GlideRecord('pm_m2m_project_stakeholder');
PO.addQuery('project');
PO.addQuery('expectationINproject_owner');
PO.query();

if (PO.next()){
g_form.setDisplay('u_project_owner' , PO.stakeholder.user.name.getDisplayValue() );

}
}

2 ACCEPTED SOLUTIONS

Hi @Jeck Manalo 

 

Yeah....Its best practice now a days to use flow designer instead of business rule on table....indeed.

 

Fix script : It is server side script similar to business rule to update records in bulk manner which you can run on demand.

E.g., If you want to update the state of incident to closed which are older that 6 months like wise...

 

another example with screenshot :

VishalBirajdar_0-1706257804034.png

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

I figured out that I just need to reconfigure my works on flow designer.

 

its now working 🙂 but thank you for those idea it's help a lot.

 

JeckManalo_0-1706261782257.png

 

View solution in original post

13 REPLIES 13

Vishal Birajdar
Giga Sage

Hello @Jeck Manalo 

 

It is not recommended to use GlideRecord() object in client script...!!!

 

Can you explain your requirement bit more so we can help you...!!!

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Hello,

 

I see.

 

the requirement is I need to display the value in u_project_owner' (Field Form) which is on the Project.

The value will be based on the stakeholders table that is linked to current Project. 

 

If you look this one its linked to Project table, and for this record I need it to display the value of Project Owner into the 2nd pic below.

JeckManalo_4-1706245235254.png

 

 

I need to display it the stakeholder value here.

 

JeckManalo_2-1706245102383.png

 

 

You need to create after business rule which run on Insert and Update.

 

You need to create the business rule on stakeholder table. Then go to Advanced tab  and write the script something below

 

var rec = new GlideRecord('name_of_project_table');

rec.<field_name_on_project table> = current.<field_name_on_stakeholder_table>;

rec.update();

 

 

Hi,

 

In stakeholders table there is difference function which I need to filter only to project owner using this query expectationINproject_owner.

 

var rec = new GlideRecord ('pm_project');
rec.addQuery('expectationINproject_owner');
 
 
rec.u_project_owner = current.rec.dmn_stakeholder_register;
 
rec.update();
})(current, previous);