This topic contains 14 replies, has 0 voices, and was last updated by GusGus 6 years, 10 months ago.

  • Author
    Posts
  • #21358

    GusGus

    How do you use nlapiResolveURL() in a Suitelet? I'm hoping to use a Suitelet to workaround permissions problems. I have a custom button set by a user event script. A client script is triggered by that button. I want to use nlapiResolveURL to open a copy of a record in edit mode but the user can not have edit permission for this record. So, I can't just use nlapiResolveURL from my client script. I was wondering if I could use it to trigger a Suitelet that was set up execute as administrator and then use nlapiResolveURL to open a copy of the record in edit mode from the Suitelet. I was hoping then the user could edit it as if they were an administrator. Will this work? How do I set up the Suitelet?
    This is a cached copy. Click here to see the original post.

  • #21359

    mwhite@hgyp.com

    This is very doable. As long as the script being called by the button press has the appropriate permissions, there should be no problem using nlapiResolveURL to call a second Suitelet to do the work.

  • #21360

    GusGus

    Thanks. The thing I don't know how to do is to use nlapiResolveURL in a suitelet to open the record copy. In my client script I have

    Code:
    var recordId= nlapiGetRecordId();
    var poNumber = record.getFieldValue('tranid');
    var url = nlapiResolveURL('SUITELET', 'customscript_mysuitelet','customdeploy_mysuitelet') + '&poNumber=' + poNumber + '&recordId=' + recordId;
    window.location = url;
    In my suitelet:

    Code:
    function openPOCopy(request, response) {
    var poTranId = request.getParameter('poNumber');
    var recordId = request.getParameter('recordId');
    var poCopyUrl = nlapiResolveURL('RECORD', 'purchaseorder', recordId, 'edit') + '&e=T' + '&memdoc=0'+'&is_custom_copy=1'+ '&poNumber='+poTranId;
    }
    I don't know what I need to add to the suitelet to have it open the url. Do I need to pass something back to the client script? Can I just open it from the suitelet?

  • #21361

    mwhite@hgyp.com

    Depending on how much you want to change, nlapiSubmitField might be more efficient (allows you to change a field without loading the record).

    nlapiSubmitField('itemfulfillment', internalId, FieldName, NewValue)

    If you're wanting the user to edit the document, it's more like this, but I didn't catch the fact that you may have wanted that. I haven't tried that approach. The script can edit the transaction with admin rights, but I don't believe the user can. Here's how you do it, though:

    var selectAddress = nlapiGetFieldValue('custrecord_hg_price_select_add ress');

    var customer = nlapiGetFieldValue('custrecord_hg_price_customer') ;

    if (selectAddress == 'T' && customer && (customer.length > 0) )

    {

    // Get Suitlet base url

    var suiteletUrl = nlapiResolveURL('SUITELET', 'customscript_select_customer_address', 'customdeploy_select_customer_address');

    //Pass the following fields as variables into the Suitelet

    suiteletUrl += '&custparam_customerId='+ customer;

    nlapiSetFieldValue('custrecord_hg_price_select_add ress','F');

    var intHeight = 520;

    var intWidth = 350;

    var scroll = 1;

    var newWindow = window.open(suiteletUrl, 'AddressSelect', 'width=' + intWidth + ',height=' + intHeight+ ',scrollbars=' +scroll);

    newWindow.focus();

    }

  • #21362

    GusGus

    I think in this case you are opening a custom form for the user to edit fields in the current record. I need to make a copy of the record and edit that. I don't want the user to edit the original record. Is there a way to create the copy from the suitelet and open it without submitting the record? I need it to open in edit mode before it is ever submitted. Originally I just had a client script that looked like this:

    Code:
    var recordId= nlapiGetRecordId();
    var record = nlapiLoadRecord('purchaseorder', recordId);
    var poNumber = record.getFieldValue('tranid');
    console.log('open po amendment');
    var url = nlapiResolveURL('RECORD', 'purchaseorder', recordId, 'edit') + '&e=T' + '&memdoc=0'+'&is_custom_copy=1'+ '&poNumber='+poNumber;
    window.location = url;
    This did exactly what I needed but the users that will be needing this function are not allowed to have edit access to purchase orders. So I thought I could funnel it through a suitelet somehow to work around the permissions issue.

  • #21363

    mwhite@hgyp.com

    You should be able to use the Suitelet in much the same way. I'd make the button push to call another suitelet and pass it the internal id of the PO to be copied.

  • #21364

    GusGus

    How do I open the url that I have created with the nlapiResolveURL function from the suitelet? I can't find an example of how that is done. In the client script I would use window.location = url. How do I do that same thing in a Suitelet?

  • #21365

    mwhite@hgyp.com

    You can do the same thing in a suitelet

  • #21366

    GusGus

    That's not working for me. I know I don't need the client script now but it should work the same way when I have the button just trigger the suitelet. So my client script:

    Code:
    var recordId= nlapiGetRecordId();
    var record = nlapiLoadRecord('purchaseorder', recordId);
    var poNumber = record.getFieldValue('tranid');
    console.log('open po amendment');
    var url = nlapiResolveURL('SUITELET', 'customscript_mysuiteletl','customdeploy_mysuitelet') + '&poNumber=' + poNumber + '&recordId=' + recordId;
    var newWindow = window.open(url);
    newWindow.focus();
    My Suitelet:

    Code:
    function openPOCopy(request, response) {
    var poTranId = request.getParameter('poNumber');
    var recordId = request.getParameter('recordId');
    var poCopyUrl = nlapiResolveURL('RECORD', 'purchaseorder', recordId, 'edit') + '&e=T' + '&memdoc=0'+'&is_custom_copy=1'+ '&poNumber='+poTranId;
    window.location(poCopyUrl);
    }
    This just opens a blank page. What am I doing wrong?

  • #21367

    mwhite@hgyp.com

    Try nlapiResolveURL('RECORD', 'purchaseorder', recordId). You're already telling it to use edit mode in the parameters you're passing.

  • #21368

    GusGus

    No, I'm only passing the purchase order number and record internal id to the suitelet. Then I'm trying to use those in the url that I am generating in the suitelet. I'm pretty sure I can't just open a window from the suitelet the same way you can in the client script. I've seen examples where you create a form or where you send html back to the client script.

  • #21369

    pcutler

    In a Suitelet, you have nlobjResponse.sendRedirect(type, identifier, id, editmode, parameters) if you want to redirect the browser from server-side code.

  • #21370

    GusGus

    Thanks pcutler. That works but it didn't solve my permissions issue. I still get an error that I need a higher level of permission to open a purchase order. I guess using the suitelet isn't the permissions workaround I thought it was. I think I'll have to continue working around it by making scripts that execute on create and edit for purchase order and making sure the user can only edit under very specific circumstances.

  • #21371

    pcutler

    Originally posted by GusGus

    View Post

    Thanks pcutler. That works but it didn't solve my permissions issue. I still get an error that I need a higher level of permission to open a purchase order. I guess using the suitelet isn't the permissions workaround I thought it was. I think I'll have to continue working around it by making scripts that execute on create and edit for purchase order and making sure the user can only edit under very specific circumstances.

    For the user to be able to view or edit a purchase order in their browser, they will need permission to that record. Suitelets only alter role/permissions for the server-side code that runs inside the Suitelet. For instance, a user without permissions to PO records can submit a suitelet that creates a PO as long as the suitelet runs as another role with the necessary permissions.

  • #21372

    GusGus

    So I could make a Suitelet that creates a custom form with all of the same info as the purchase order I want to copy, then the user could edit and submit that form and the suitelet could submit a PO with the data from the custom form. That is, as long as the suitelet is executing with a role that has permission to create purchase orders.

You must be logged in to reply to this topic.