Redirect URL in JavaScript

edited October 31, 2019 in Questions
I was searching for the code to redirect to a page within a Salesforce org. I couldn't find it so here it is. Note "newOrderId.Id" is whatever the variable is for the ID to your new page. Hope this helps someone. 

//Redirect to New URL
    var URL = '../../' + newOrderId.Id; 
    var win = window.open(URL, '_blank');

Comments

  • edited October 31, 2019
    Hi Luzie,

    I have never used curly brackets within my JS snippets.
  • Matthew LeahyMatthew Leahy ✭✭✭
    edited October 31, 2019
    Hey Tami, here is some example Javascript code that may help you out.

    var $ = skuid.$;
    var field = arguments[0];
    var value = arguments[1];

    switch( field.mode ){
        case 'edit':
            skuid.ui.fieldRenderers[field.metadata.displaytype].edit( field, value );
            break;

        case 'read':
            var cellElem = field.element;
            var url = '/cp/scenariodetails/'+field.row.id;
            $( '<a href='+url+'>'+value+'</a>' ).appendTo( cellElem );
            break;
            
        default:
            var cellElem = field.element;
            var url = '/cp/scenariodetails/'+field.row.id;
            $( '<a href='+url+'>'+value+'</a>' ).appendTo( cellElem );
        break;
    }

    Let us know if it gets you there. Thanks.
  • Luzie BaumgartLuzie Baumgart 🛠️ 
    edited October 31, 2019
    Tami, I was on a wrong path here, let me delete my reply to not confuse any more users. Matt will post his response again.
  • Matthew LeahyMatthew Leahy ✭✭✭
    edited October 31, 2019
    Hey Tami, here is some example Javascript code that may help you out.

    var $ = skuid.$;
    var field = arguments[0];
    var value = arguments[1];

    switch( field.mode ){
        case 'edit':
            skuid.ui.fieldRenderers[field.metadata.displaytype].edit( field, value );
            break;

        case 'read':
            var cellElem = field.element;
            var url = '/cp/scenariodetails/'+field.row.id;
            $( '<a href='+url+'>'+value+'</a>' ).appendTo( cellElem );
            break;
            
        default:
            var cellElem = field.element;
            var url = '/cp/scenariodetails/'+field.row.id;
            $( '<a href='+url+'>'+value+'</a>' ).appendTo( cellElem );
        break;
    }

    Let us know if it gets you there. Thanks.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!