sMRVS values not recognized in flow

JonathanR149250
Tera Contributor

Hello,

 

Any advice would be greatly appreciated. I am building a catalog item that takes values from 2 different MRVSs (mrvs_adobe) & (mrvs_c4c) and takes those values and pushes them to a 3rd MRVS ('Requested Access') onSubmit, which would allow the view of ('Requested Access') on the RITM. Initially I thought the issue was the values needed to be populated prior to the REQ being generated. My solution was to add a confirm box having the user verify if their request was accurate and if they select "Ok" it would submit the form formally, if not go back to the catalog request. This did allow the values to be pushed to ('Requested Access') when the confirmation box trigger but even when the form was submitted, the flow does not recognize the values from ('Requested Access').

 

Right now I just discovered that if I Cancel the confirmation box, then submit the form again but hit Ok to allow the form to generate the flow will now recognize the values.

 

I am not a huge coder so i'm sure there may be gaps in the logic I am using, if anyone has any ideas on what may solve this please let me know.

 

Code being used: 

 

 

 

function onSubmit() {

    //Type appropriate comment here, and begin script below

    //Get MRVS Values
    var obj = (g_form.getValue('Requested Access') != 0) ? JSON.parse(g_form.getValue('Requested Access')) : [];

    var vs_adobe = g_form.getValue('Adobe Application Details') || '[]';
    var mrvs_adobe = JSON.parse(vs_adobe);

    var vs_c4c = g_form.getValue('C4C Application Details') || '[]';
    var mrvs_c4c = JSON.parse(vs_c4c);
   
    //Populate Requested Access MRVS with Adobe Application Details MRVS
    for (var i = 0; i < mrvs_adobe.length; i++) {
        obj.push({
            role_requested: mrvs_adobe[i].role_adobe,
            application_requested: mrvs_adobe[i].application_adobe
        });
        g_form.setValue('Requested Access', JSON.stringify(obj));
    }

    //Populate Requested Access MRVS with C4C Application Details MRVS
    for (var i = 0; i < mrvs_c4c.length; i++) {
        obj.push({
            role_requested: mrvs_c4c[i].role_c4c,
            application_requested: mrvs_c4c[i].application_c4c,
            environment_requested: mrvs_c4c[i].environment_c4c
        });
        g_form.setValue('Requested Access', JSON.stringify(obj));
    }

    // Retrieve the values of the specified fields
    var confirm_application = JSON.parse(getValue('requested_application') || '[]');
    var recurrence = g_form.getValue('recurrence');


    var confirmationMessage = 'Please review the below selected information';
    if (recurrence === "Once") {
        confirmationMessage += ' for a single event.\n' +
                               'Click OK to continue or Cancel to return to the form.\n' +
                               'Application: ' + confirm_application + '\n';
    } else {
        confirmationMessage += ' for recurrence.\n' +
                               'Click OK to continue or Cancel to return to the form.\n' +
                               'Application: ' + confirm_application + '\n';
    }

    // Display the confirmation dialog
    var answer = confirm(confirmationMessage);

    // If the user clicks "Cancel", prevent the form submission
    if (!answer) {
        return false;
    }
}

 

1 ACCEPTED SOLUTION

JenniferRah
Mega Sage

Does this code ever work? Does it give any errors when it doesn't?

 

Right off the bat, I see that you are doing a getValue and using what appears to be the display name of the MRVS and the variables. You will need to use the internal variable names for that. So if it never works, that's the first thing I would do.

 

Also, are you doing this from a Portal or the SN client?

View solution in original post

3 REPLIES 3

JenniferRah
Mega Sage

Does this code ever work? Does it give any errors when it doesn't?

 

Right off the bat, I see that you are doing a getValue and using what appears to be the display name of the MRVS and the variables. You will need to use the internal variable names for that. So if it never works, that's the first thing I would do.

 

Also, are you doing this from a Portal or the SN client?

Thanks for the feedback! I am still new to the platform so I’m unable to answer if this is being done from a portal or client. But the code does work as it shows in the “MRVS populated on RITM” attachment the variables show up but they are not recognized in flow designer. I will go and update variables to their internal name. But the idea is to have this working on the service portal. 

Any additional guidance would be greatly appreciated!

JonathanR149250
Tera Contributor

I have updated the code to run onChange and have it contain the internal name on all variables, it is now running on the service portal as I had hoped, as well as shows the values in the flow logic "for each" Here is the new code:

function onChange(control, oldValue, newValue, isLoading) {
    // Prevent running the script when the form is loading
    if (isLoading) {
        return;
    }
    
    if (newValue) {
        // Fetch the value of 'Requested Access' field (as JSON)
        var requestedAccess = g_form.getValue('sar_requested_access_mrvs') || '[]';
        var obj = JSON.parse(requestedAccess);

        // Fetch the Adobe Application Details and C4C Application Details
        var vs_adobe = g_form.getValue('sar_adobe_mrvs') || '[]';
        var mrvs_adobe = JSON.parse(vs_adobe);

        var vs_c4c = g_form.getValue('sar_c4c_mrvs') || '[]';
        var mrvs_c4c = JSON.parse(vs_c4c);

        // Process Adobe data and add to 'Requested Access'
        for (var i = 0; i < mrvs_adobe.length; i++) {
            obj.push({
                role_requested: mrvs_adobe[i].role_adobe,
                application_requested: mrvs_adobe[i].application_adobe
            });
        }

        // Process C4C data and add to 'Requested Access'
        for (var i = 0; i < mrvs_c4c.length; i++) {
            obj.push({
                role_requested: mrvs_c4c[i].role_c4c,
                application_requested: mrvs_c4c[i].application_c4c,
                environment_requested: mrvs_c4c[i].environment_c4c
            });
        }

        // Set the updated value back to 'Requested Access'
        g_form.setValue('sar_requested_access_mrvs', JSON.stringify(obj));
    }
}