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

Hi @Jeck Manalo 

 

Okh got it...!!

 

You can write Business rule on 'pm_m2m_project_stakeholder' table with condition

 

VishalBirajdar_0-1706255600866.png

 

Script :

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

	/*1. Get the value of project */
	var getProject = current.getValue('project');  //will get sys_id of project record
    
	/*2. Get value of Stakeholder */
	var getStakeholder = current.getValue('stakeholder');

	/*3.Glide record on Project table */
	var grProject = new GlideRecord('pm_project');
	grProject.addQuery('sys_id',getProject);
	grProject.query();

	if(grProject.next()){
		/* 3.1 Update product owner with stakeholder */
		grProject.setValue('u_product_owner',getStakeholder);
		grProject.update();
	}

	/* you can improve your code as per your need */

})(current, previous);

 

 

**Note : This will run for new records or if it gets updated.

For existing record you can do it with fix script.

 

Hope this helps...!!

 

 

 

Vishal Birajdar
ServiceNow Developer

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

I think its just similar on my flow designer process which will update the field once the stakeholders created/updated.

 

JeckManalo_0-1706256349294.png

 

Stakeholders data is already there since it was just transferred to project table so there no need to update/create new data.

 

Can you tell me what fix script you mean ?

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

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