When an assessment is completed by stakeholder it needs to be redirected to current demand ?

VedhR
Tera Contributor

when a stakeholder completes his assessment, it needs to be redirected to current demand, i have created a business rule and a client script but it is not working. 

 

Business rule code:

 

 VedhR_0-1729167684985.png

 

 
Client Script: 
VedhR_1-1729167718541.png

 


could you please help me on the code.
 
Thank you
2 REPLIES 2

Siddhesh Jadhav
Kilo Sage

Hi @VedhR ,

 

I’ve revised your code for the business rule and client script to ensure proper redirection after the stakeholder completes their assessment. Please find the updated code below:

 

Business Rule 

Make sure the business rule is set to after the record is updated, and adjust the code as follows:

 

(function executeRule(current, previous) {
    var demandID = current.trigger_ID;
    var demandURL = '/dmn_demand.do?sys_id=' + demandID;

    gs.addInfoMessage('Redirecting to demand record'); // Fixed the quote
    gs.getSession().putClientData('redirect_url', demandURL); // Set the redirect URL

    // Note: Do not use sendRedirect in a business rule
})(current, previous);

 


Client Script
The client script looks good; ensure it is set to onLoad. Here’s the code with proper formatting:

 

function onLoad() {
    var redirectURL = g_user.getClientData('redirect_url');
    if (redirectURL) {
        window.location.href = redirectURL; // Redirect to the URL
    }
}

 

 

Important Notes:
1. Business Rule Settings:
Ensure the business rule is set to run after the record is updated. If it runs before the update, the client script won't be able to redirect correctly because the changes won't be saved yet.

 

2. Redirecting with sendRedirect:
The gs.sendRedirect() method won't work in a business rule for redirecting users. Instead, you're already setting the URL in the client data, which is the correct approach.

 

3. Session Management:
Check that there are no other scripts or conditions interfering with the session data being stored. The putClientData method should work as expected unless overridden elsewhere.

 

If this helps, please mark it as accepted and helpful!

 

Thank you,
Siddhesh Jadhav

Hi @Siddhesh Jadhav

 

Thank you for your response.

 

I have tried the code but it didn't work

 

Business rule:

Table: Asmt_assessment_instance

when to run: After update

condition: state is complete

 

code:

 var demandID = current.trigger_ID;
    var demandURL = '/dmn_demand.do?sys_id=' + demandID;
    gs.addInfoMessage('Redirecting to demand record'); // Fixed the quote
    gs.getSession().putClientData('redirect_url', demandURL); // Set the redirect URL
 
Client script:
function onLoad() {
   var redirectURL = g_user.getClientData('redirect_url');
    if (redirectURL) {
        window.location.href = redirectURL; // Redirect to the URL
    }
}
 
when assessment is completed, this is what happening!
VedhR_0-1729178578547.png

and also here is the Ui action 

VedhR_1-1729178639420.png