Catalog Client script for mandatory fields

Gemma4
Mega Sage

Hi everyone,

If possible can I please get some expertise on what might be causing a conflict with my catalog client script. Attached and below are the details. The script is making the variables required after submit for users with the pm user role in the platform but not the portal. I need the variables required  in both the portal and platform. See attached and below is script 

 

thank you in advance for any feedback you can provide!

 

 

//Karen has the role PM and mandatory fields are not required for her
//PM role also displays visiblity to modules 
//Users with PMSubmitter role will be required to complete Mandatory fields
 
function onLoad() {
 
 
 
 
 
//  if (g_user.hasRole('pmsubmitter')){
//  if (g_user.hasRoleExactly('pmsubmitter')){
if (g_user.hasRoleExactly('pm_user')){
//  g_form.setDisplay('effort_estimate', false);
 
 
//  g_form.setMandatory('business_need', false);
  g_form.setMandatory('business_need', true);
  g_form.setMandatory('effort_estimate', true);
  g_form.setMandatory('objectives', true);
  g_form.setMandatory('key_deliverables', true);
  g_form.setMandatory('key_dependencies', true);
  g_form.setMandatory('assumptions', true);
  g_form.setMandatory('constraints', true);
  g_form.setMandatory('risks', true);
  g_form.setMandatory('out_of_scope', true);
  g_form.setMandatory('workaround_identified', true);
  g_form.setMandatory('resource_requirements', true);
  g_form.setMandatory('estimated_costs', true);
  g_form.setMandatory('project_manager_assignment', true);
 
 
  }
 
 
  else{
 
 
 // g_form.setDisplay('effort_estimate', true);
 
 
//  g_form.setMandatory('business_need', true);
  g_form.setMandatory('business_need', false);
g_form.setMandatory('effort_estimate', false);  
g_form.setMandatory('objectives', false);  
g_form.setMandatory('key_deliverables', false);
    g_form.setMandatory('key_dependencies', false);
    g_form.setMandatory('assumptions', false);
    g_form.setMandatory('constraints', false);
    g_form.setMandatory('risks', false);
    g_form.setMandatory('out_of_scope', false);
    g_form.setMandatory('workaround_identified', false);
    g_form.setMandatory('resource_requirements', false);
    g_form.setMandatory('estimated_costs', false);
    g_form.setMandatory('project_manager_assignment', false);
 
 
 
  }
 
 
 
 
}
5 REPLIES 5

Niklas Peterson
Mega Sage
Mega Sage

Hi,

Change the UI Type from Desktop to All to have it run on the portal as well.


Regards,
Niklas

The problem is if I select all it does make the fields required on both the portal and the platform but it makes the variables required before it is submitted. I need the variables to only display required after the request is  submitted- on both the portal and platform. Is this possible? 

 

Hello Gemma,

 

Try to execute the

	var category = getParameterValue('sysparm_category');
	alert(category!='');
	
	function getParameterValue(name) {  
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");  
	var regexS = "[\\?&]" + name + "=([^&#]*)";  
	var regex = new RegExp(regexS);  
	var results = regex.exec(top.location);  
	if (results == null) {  
		return "";  
	} else {  
		return unescape(results[1]);  
	} 
}

following script.

//Type appropriate comment here, and begin script below
function onLoad() {
    var category = getParameterValue('sysparm_category');
    if (category == '') {
        //  if (g_user.hasRole('pmsubmitter')){
        //  if (g_user.hasRoleExactly('pmsubmitter')){
        if (g_user.hasRoleExactly('pm_user')) {
            //  g_form.setDisplay('effort_estimate', false);
            //  g_form.setMandatory('business_need', false);
            g_form.setMandatory('business_need', true);
            g_form.setMandatory('effort_estimate', true);
            g_form.setMandatory('objectives', true);
            g_form.setMandatory('key_deliverables', true);
            g_form.setMandatory('key_dependencies', true);
            g_form.setMandatory('assumptions', true);
            g_form.setMandatory('constraints', true);
            g_form.setMandatory('risks', true);
            g_form.setMandatory('out_of_scope', true);
            g_form.setMandatory('workaround_identified', true);
            g_form.setMandatory('resource_requirements', true);
            g_form.setMandatory('estimated_costs', true);
            g_form.setMandatory('project_manager_assignment', true);
        } else {
            // g_form.setDisplay('effort_estimate', true);
            //  g_form.setMandatory('business_need', true);
            g_form.setMandatory('business_need', false);
            g_form.setMandatory('effort_estimate', false);
            g_form.setMandatory('objectives', false);
            g_form.setMandatory('key_deliverables', false);
            g_form.setMandatory('key_dependencies', false);
            g_form.setMandatory('assumptions', false);
            g_form.setMandatory('constraints', false);
            g_form.setMandatory('risks', false);
            g_form.setMandatory('out_of_scope', false);
            g_form.setMandatory('workaround_identified', false);
            g_form.setMandatory('resource_requirements', false);
            g_form.setMandatory('estimated_costs', false);
            g_form.setMandatory('project_manager_assignment', false);
        }
    }

    function getParameterValue(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(top.location);
        if (results == null) {
            return "";
        } else {
            return unescape(results[1]);
        }
    }
}

Hi,

These checkboxes controls where to apply the logic. So if you don't want it to run on the Catalog Item but only on the Requested Item then untick this

NiklasPeterson_0-1693544985621.png

However, it may be more complex than that. Usually an End User is not viewing the Requested Item on the portal using the ticket form but rather a page with summary widgets just to view it. 

 

Regards,
Niklas