Validated Redirect

When the user selects an option from a drop menu (column), I would like the chosen value to be used to determine the redirect. If the user selects 'Value1' or 'Value2', then upon Form Submit, they should be redirected to https://www.site1.com. If the user selects 'Any other Value', then upon Form Submit, they should be redirected to https://www.site2.com.

I have read many posts trying to gather pointers, but I am stuck and sending it to the community for consideration. What am I missing?

The current behavior redirects to https://www.site2.com, regardless of the values chosen.

fd.spSaved(function(result) {
 
  if (fd.field('column').value == 'Value1' || fd.field('column').value == 'Value2') {
      result.RedirectUrl = "https://www.site1.com";
  }
      
  else result.RedirectUrl = "https://www.site2.com";
    

});

fd.field('submitform').value = 'Submit Form';
return fd.save();

Many thanks!

Dear @shedev,
I've tested your code with this and it runs just fine:

fd.spSaved(function(result) {
 
  if (fd.field('Title').value == 'Value1' || fd.field('Title').value == 'Value2') {
      result.RedirectUrl = "https://www.google.com";
  }
      
  else result.RedirectUrl = "https://www.plumsail.com";
    

});

return fd.save();

If your code doesn't run, most likely the value that you check doesn't match. Check the field type that you use and how it stores its value here - SharePoint field types — SharePoint forms

Thank you @Nikita_Kurguzov as always for your clear and helpful guidance. I am still able to only accomplish a redirect to the 'else' location.

I am using a SUBMIT CONTROL and the General Click action with the JavaScript below. The SP column 'roles' is a DropDown CHOICE field. I am using no other JavaScript via the JS console, and basic CSS to hide the built-in toolbar.

In the CHOICE column, there are five (5) options to choose from in the DropDown. Two (2) of those values are declared in the first statement (fd.field('roles').value == 'A Job Title 1' || fd.field('roles').value == 'A Job Title 2'). The remaining choices should be caught by 'else'. I may add more if statements to redirect to three+ URLs, but for now, the two (as you used in your example) are great for testing.

One last piece that may or may not be of interest - both locations are SharePoint sites in our tenant, but unique pages.

I have verified that the column is named 'roles' and that the values match for 'A Job Title 1' and 'A Job Title 2'. I am guessing this is something simple, but I can't quite find it. I will keep trying and thank you again.

fd.spSaved(function(result) {
 
  if (fd.field('roles').value == 'A Job Title 1' || fd.field('roles').value == 'A Job Title 2') {
      result.RedirectUrl = "https://www.plumsail.com";

  }    
    else result.RedirectUrl = "https://www.google.com";
 
});

return fd.save();

Dear @shedev,
You can test that the code is running with some alerts, for example:

fd.spSaved(function(result) {
  alert(fd.field('roles').value);
  if (fd.field('roles').value == 'A Job Title 1' || fd.field('roles').value == 'A Job Title 2') {
      alert('True!');
      result.RedirectUrl = "https://www.plumsail.com";

  }    
  else {
       alert('Else!');
       result.RedirectUrl = "https://www.google.com";
  }
});

return fd.save();

@Nikita_Kurguzov - It occurred to me after a few hours of testing, retesting, scrapping, and other attempts to achieve a successful conditional redirect that this is a +New List item form. There are no values to satisfy as the item has not yet been created.

I shifted my thinking and attempted to leverage the Plumsail controls, creating a hidden plain text field to capture the 'on change' text and use it to perform the redirect. The text field indeed captures the text value of the SP drop menu selection and finally processes the desired statements.

In the General > Click panel:

fd.spSaved(function(result) {
  if (fd.control('PlumsailPlainTextControl').text == 'Title1' || fd.control('PlumsailPlainTextControl'').text == 'Title2') {
  result.RedirectUrl = "https://www.plumsail.com";

  }    
  else {
       //alert('Else!');
       result.RedirectUrl = "https://www.google.com";

  }
});

return fd.save();

In the JS panel:

fd.spRendered(function() {

    function ByRole() {
        if (fd.field('UserRole').value == 'Title1') {  
             fd.control('PlumsailPlainTextControl').text = 'Title1';
        }
        else  if (fd.field('UserRole').value == 'Title2') {  
             fd.control('PlumsailPlainTextControl').text = 'Title2';
        }
        else if (fd.field('UserRole').value == 'Title3') {  
             fd.control('PlumsailPlainTextControl').text = 'Title3';
        }
        else if (fd.field('UserRole').value == 'Title4') {  
             fd.control('PlumsailPlainTextControl').text = 'Title4';
        }
      
        else fd.field('ByRole').value = '*' ;
        
}

    // Calling ByRole value changes
    fd.field('ByRole').$on('change', ByRole);

    // Calling ByRole on form loading
    ByRole();

});

Dear @shedev,
It's irrelevant what form you use, as long as the field is on the form and can be edited - its value can be retrieved with code. My example above with the title field works.

Do you get any messages from alerts? Are you sure the second URL is even used for redirection? Maybe no code is working at all, and you're not being redirected.