javascripthttp-redirectnetsuitesuitescript2.0clientscript

How to redirect to Custom Record in Create mode in SuiteScript 2.0?


I'm trying to redirect to a Custom Record from a custom Button from Sales Order. Button function is given below, I need to get rectype(496) parameter by passing the Custom record Id (custrecord_gotorecord) or any other way to do the same?

function openCustomRecordCreate() { 
            var currRec = currentRecord.get();
            var currentRecordId = currRec.getValue({
                fieldId: "id"
            });
            window.open("/app/common/custom/custrecordentry.nl?rectype=496&soID=" + currentRecordId + "&end=true", '_self');
        }

Solution

  • You can use the N/url module to get the correct URL of a record given the record type and, optionally, the record id. Using this code will redirect to a custom record in create mode and it works in a client script.

    You can use the string value for the record type so it will work in any environment, since the numeric ids can change between accounts (i.e., sandbox to production).

    Also, make sure you're using customrecord_gotorecord, not the shorter version, custrecord_gotorecord for the recordType parameter. The shorter version is for custom field ids.

    var redirectUrl = url.resolveRecord({
      recordType: 'customrecord_gotorecord',
      recordId: id,
      isEditMode: true
    });
    
    window.open(redirectUrl);