We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Limit short description to max 40 characters for Projects and Demands

PaulaaO
Mega Sage

Hi Community,

 

I have been asked to configure the fields that represent project and demand names so users would be restricted to setup names longer than 40 characters.

 

The field is short_description and it's a shared field from the extended tables (task for demand and planned_task for project) which means I cannot update the dictionary record.

 

I have created a Client Script and a Business Rule to try and drive the behaviour, however I am struggling to enforce it when I create the project from a template (link: To create project from a template click here.)

 

The Client Script (onChange) is as following (it's similar for Demand and for Project)

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (newValue.length > 40) {
        alert(getMessage('Project name must be 40 characters or less.'));
        // Reset the field value to the previous value
        g_form.setValue('short_description', oldValue);
    }
}

 

The Business Rule (before insert) is as following (only for Project)

 

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

	// check if Project name exceeds 40 characters
	if (current.short_description.length > 40) {
		current.setAbortAction (true);
		gs.addErrorMessage('Project name must be 40 characters or less');
	}

})(current, previous);

 

What am I missing and what do I need to do to make this work?

 

Thank you.

 

Paula

 

 

8 REPLIES 8

Dr Atul G- LNG
Tera Patron

HI @PaulaaO 

 

What is the current length? & what is business case to reduce it.

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

Hi Atul - the current length is 160 and the business case is that in our Finance system project names can only have max 40 characters; they download and use info from SN to generate budget details.

Anurag Tripathi
Mega Patron

 

So if I understand correctly your client scripts is working fine, but the BR is not as it fails when you create project via template.

-Anurag

correct 🙂