Need to make Stakeholder Related List Mandatory for Projects

MBarrott
Mega Sage

I want to ensure that there is at least one record present in the Stakeholder related list before creating a project. 

 

I've created a Business Rule for this but it doesn't appear to be working, am I pointing the GlideRecord at the correct table?

 

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

	// Add your code here
	var stk = new GlideRecord("dmn_stakeholder_register");

	stk.addEncodedQuery("parent=" + current.sys_id);

	stk.query();

	if(!stk.next())
	{
		gs.addInfoMessage("Please link a Stakeholder Record at the bottom.");

		action.setRedirectURL(current);

		current.setAbortAction(true);
	}

})(current, previous);
2 REPLIES 2

Siddhesh Gawade
Mega Sage
Mega Sage

You can confirm the glideRecord table by checking the existing stakeholder list records.

 

Also the make sure the business rule should be on before insert on project table.

 

And in second line of code you are checking incorrect sys_id for parent field. You should be the sys_id of record were this project is creating or the record were the related list is present.

 

Try:  current.parent.sys_id         // instead of parent you can also use another field which we give you the sys_id of record from were you wanted to create the project.

 

Kindly mark my answer as Correct and helpful based on the Impact.



Kindly mark the answer ✔️ Correct or Helpful ✔️ If it addresses your concern.



Regards,

Siddhesh

gajananvw
Tera Expert

Hi use below script.

var stk = new GlideRecord("pm_m2m_project_stakeholder");
stk.addEncodedQuery("project=" + current.sys_id);
stk.query();
if(!stk.hasNext())
{
gs.addInfoMessage("Please link a Stakeholder Record at the bottom.");
action.setRedirectURL(current);
current.setAbortAction(true);
}