Order Guide disable "Next" button

booher04
Tera Guru

I'm trying to disable the "Next" button(grey out) if the logged in user has a specific role.  The need is to hide fields and display a link to an external page if the user has a certain role.

 

I have the fields hidden and link displaying correctly but I can't get the next button to disable correctly.  It disables(greys out) for anyone not just the user with the role I created.

 

Here is the UI Policy I am using to hide/display variables if user does not have the role:

 

function onCondition() {
var Userx = g_user.hasRoleExactly('fnf_virtual_machine_no_redirect');
        if (Userx.toString() == 'false' ) {
	
		g_form.setDisplay('label_ewr', true);
		g_form.setValue('cb_redirect', 'true');
        g_form.setVisible('sql_cluster', false);
		g_form.setMandatory('deployment_location', false);
		g_form.setVisible('deployment_location', false);
}

}

 

 

I tried the below in a client script to run onLoad and I also tried adding in the code above and it did not work: 

this.jQuery('#submit').prop('disabled', true);
 

 

function onLoad() {
var Userx = g_user.hasRoleExactly('fnf_virtual_machine_no_redirect');
        if (Userx.toString() == 'false' ){
   setTimeout(function() {
        this.jQuery('#submit').prop('disabled', true);
    }, 2000);
}
}

 

 

1 ACCEPTED SOLUTION

booher04
Tera Guru

I was able to achieve what I needed by creating an onLoad catalog client script on the order guide:  I had to put in a timeout function in order to get it to work correctly

function onLoad() {
var Userx = g_user.hasRoleExactly('fnf_virtual_machine_no_redirect');
        if (Userx.toString() == 'false' ){
   setTimeout(function() {
        this.jQuery('#submit').prop('disabled', true);
    }, 2000);
} else var Userx = g_user.hasRoleExactly('fnf_virtual_machine_no_redirect');
        if (Userx.toString() == 'true' ){
   setTimeout(function() {
        this.jQuery('#submit').prop('disabled', false);
    }, 2000);
}}

 

View solution in original post

5 REPLIES 5

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @booher04 ,

 

Basically what i understand is that your trying to restric the user with role 'fnf_virtual_machine_no_redirect'.

 

1. Create a client script that sets all the fields readonly using below script.

var getFields = g_form.getEditableFields();
for(var i=0;i<getFields.length;i++)
{
g_form.setReadOnly(getFields(i),true);
}

 

2. Create a variable which has the hyper link to external site. And that variable must be visible if the user qualifies for that role.

 

3. If necessary you can use addinfoMessage(); to show why the reason and ask for redirection.

 

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Sohail - thanks for the reply. So On the order guide I need to restrict any user that does not have the role mentioned from being able to click "Next" on the order guide first page.  

You can create a Advance UI Policy with the below script and make sure you check for role condition 

 

- Configure your Catalog UI Policy as below:

-- Active = true

-- When to Apply = no conditon in your case just chekc for role in scirpt

-- Run scripts = true

-- Run scripts in UI type = All (IMPORTANT)

 

- Execute if true script:

function onCondition() {

if(g_form.hasroleExactly('your role here')){
   this.jQuery('#submit').prop('disabled', true); // or #submit-btn (inspect your HTML first)
}
}
 

- Execute if false script:

function onCondition() {	
    this.jQuery('#submit').prop('disabled', false); // or #submit-btn (inspect your HTML first)
}
 

 

 

if needed create onLoad as well...

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Thanks Sohail - I used the script provided and I get an error saying javascript error in browser.  I tried changing g_form to g_user but it doesn't seem to do anything.  

 

I'm wondering if there needs to be a Timeout added to the script so it waits for a few seconds?