Search code examples
suitescriptsuitescript2.0

How to get navigated to a new record through url.resolveRecord() in suitescript 2.0?


I have a clickable sublist field, on clicking, user should be navigated to an employee record in create mode with some field values copied from my custom record to employee rec (as params).

I tried using resolveRecord() API, the existing employee record opens if i put any id, but because i want the same window to be navigated to an new employee record, i cannot know its internal id.

Can anyone guide me what should i do? how would i make this work and how to pass params? I am new in development.

My code:

var hyperlink = '<a href ="https://system.eu2.netsuite.com';
    var hyperEnd = '">View</a>';

      sublist.setSublistValue({
        id: 'custpage_view',
        line: 2,
        value: hyperlink + url.resolveRecord({
          recordType: 'employee',
          recordId: whatToPutHere,
          isEditMode: true,
          params:{

          }
        }) + hyperEnd
      });

Solution

  • You need to ignore the SuiteScript 2.0 API Documentation where it says that the options.recordId is required, it is not.

    Omit the recordId parameter and it will provide a link to a NEW record of the specified recordType.

    Generic example to get a link to a new Employee record:

    url.resolveRecord({
        recordType: record.Type.EMPLOYEE,
        isEditMode: true,
        params:{}
    })
    

    Specific answer to the asked question:

    var employee_firstname = "John";
    var employee_lastname = "Doe";
    var employee_phone = "0123456789";
    
    var link_url = url.resolveRecord({
        recordType: record.Type.EMPLOYEE,
        isEditMode: true,
        params: {
            'record.firstname':employee_firstname,
            'record.lastname':employee_lastname,
            'record.phone':employee_phone
        }
    });
    
    sublist.setSublistValue({
        id: 'custpage_view',
        line: 2,
        value: '<a target="_blank" href="'+link_url+'">View</a>'
    });