This topic contains 8 replies, has 0 voices, and was last updated by pcutler 6 years, 6 months ago.
-
AuthorPosts
-
November 29, 2017 at 1:29 pm #21479
GusGusIs there a way to make a copy of a record, set some fields and load that copy in edit mode without first submitting it?
This is a cached copy. Click here to see the original post. -
November 29, 2017 at 4:08 pm #21480
jmkplessersYou may be able to use the request parameter passed to the beforeLoad function described here:
https://netsuite.custhelp.com/app/an…/kw/beforeLoad
Use nlapiResolveURL to create a url for the 'create' page of the record you are trying to copy and add some custom parameters to the query string.
The request parameter in the beforeLoad function deployed to that record should contain those parameters when the user's browser attempts to access that url.
Code:
var url = nlapiResolveURL('RECORD', 'your_record_type') + '&your_custom_parameter=' + your_value;
// then navigate to that urlCode:
function beforeLoad(type, form, request) {
if (request.getParameter('your_custom_parameter')) {
// copy values from an existing record and set some fields
}
}
GusGus replied on 11/30/2017, 08:12 AM: I had looked at that function because I saw you could open a record in edit mode with it. That might work. The only problem is that I need an exact copy of another record and it’s a purchase order. Do you know if there an easy way to go through the whole record and copy all of the fields and sublists over or am I going to have to name each field?
-
November 30, 2017 at 8:51 am #21481
jmkplessersIt looks like the copy url is created by resolving the url of the record being copied in edit mode and then adding the url parameter cp=T.
Code:
var url = nlapiResolveURL('RECORD', recordType, recordToCopyId, 'edit') + '&cp=T' + '&is_custom_copy=1';Code:
function beforeLoad(type, form, request) {
if (type === 'copy' && request.getParameter('is_custom_copy')) {
// should have original record's values
// your logic here
}
}
GusGus replied on 12/22/2017, 12:37 PM: I finally got back to working on this. The problem with the nlapiResolveURL with the above parameters is that it opens the same record in edit mode instead of a copy of that record. It works like a save as instead of make a copy. I’m just saving over the old record instead of making a copy of the record. So I looked at the url when you select make a copy, replaced ‘&cp=T’ with ‘&e=T’ + ‘&memdoc=0’, now it works. I have no idea what those things mean, but it worked!
-
November 30, 2017 at 9:43 am #21482
GusGusOk, I'm trying to figure out how to execute this within a workflow triggered by purchase order creation. I have it set up so that when you press a custom button there is a custom action that executes a script that makes a copy of the current purchase order, sets some other custom fields, submits it and returns the record. Then I have a Go To Record action that opens that PO copy in edit mode. It would be better to not have to submit that copy before the user even gets a chance to make edits to it in case they want to cancel it, then the record copy will not still persist. That's what led to my question
So how do I fit this code into the workflow?
Would the creation of the url be a custom action? How do I actually open the record copy when the user presses the custom button?
Would the before load be a user event script deployed to purchase order and not made into a custom workflow action?
-
November 30, 2017 at 1:11 pm #21483
jmkplessersI am not sure how to fit the code into the workflow. Whether or not it can be part of the custom action depends on if the action runs client side or server side.
My approach would be to run the following client side code once the user presses the button.
Code:
var url = nlapiResolveURL(…)
window.location = url;
If the action runs server side you may be able to do something with nlapiSetRedirectURL.Accessing the url should trigger the beforeLoad function as long as it is a user event script deployed to the purchase order record.
GusGus replied on 11/30/2017, 01:20 PM: Ok, thank you! I think I can work with that information.
-
January 3, 2018 at 3:38 pm #21484
GusGusjmkplessers, is there a way to put the nlapiResolveURL() function that opens the copy of the record in a suitelet and have it open it from there? I have everything set up and it works great except that the users who need this don't have edit permission for this record type. I was wondering if I could get around that by triggering a client script with my custom button, then using nlapiResolveURL() from there to open a suitelet, and then use nlapiResolveURL() again in the suitelet to open the record copy in edit mode, then have the suitelet run as admin. The only other option I can think of is to stop certain roles from being able to submit a record when they edit. I was hoping I could find a better work around.
-
January 6, 2018 at 10:51 am #21485
pcutlerThe URL for copying a PO is:
Code:
nlapiResolveURL('RECORD', 'purchaseorder', INTERNAL_ID_GOES_HERE, true) + '&memdoc=0';
If you need to specify some field values in the URL, you can set them as follows:Code:
nlapiResolveURL('RECORD', 'purchaseorder', 45778, true) + '&memdoc=0&record.memo=MY%20MEMO';
GusGus replied on 01/08/2018, 02:17 PM: Oh, neat, so I can set fields right from the url?
-
May 2, 2018 at 12:56 am #21486
pcutlerGusGus – The URL and URL parameters are available in the before load user event, not the before submit event. If you want to access them in the before submit event, you need to first read them in the before load field and store them in fields, a custom record, or somewhere else.
GusGus replied on 05/02/2018, 03:06 PM: Is there a way to set a field in a transaction record when before loads in edit mode that will not be saved if the user cancels or leaves the browser screen? I need to flag the record as being in edit mode by way of my custom button but if the user leaves before submitting changes I want to be able to wipe out that flag.
I had moved away from using a user event script for the button and went back to doing everything in the workflow. However, now my issue is that if the user cancels or leaves the browser window I need to know so I can exit my workflow. I have a transition on after record submit but if the record isn’t submitted I need to exit the workflow. Instead I get stuck in the state before the record submit. If I make a transition to exit the workflow, I don’t know how to pick up on it since I anything I set in the before submit won’t be set if the record is not submitted.
So, anyway, now I was thinking of going back to the user event button creation, using a client script to load the record in edit mode, and then triggering the workflow only when the record is submitted. My issue with that comes back to my first paragraph. When using scripts to load the record in edit mode, I’m not sure how to determine that this record is in edit mode because the user clicked my custom button and not because they clicked the edit button. Whew…
-
May 2, 2018 at 3:12 pm #21487
pcutlerIt sounds like you may be asking about a custom field with the "Store Value" checkbox UNCHECKED. You can set those fields in the before load user event when a record is being edited.
GusGus replied on 05/02/2018, 03:28 PM: I assume that will only work if I go back to using scripts for the button and not using the workflow until before submit. Otherwise if I try to transition by using a flag on the record, the transition to leave the workflow will be triggered whether not I submit because I can only add a condition to the transition. The other triggers have to do with the record loading or being submitted. Does that make sense? Do I need to move away from using the workflow to display the buttons and deal with the record before the changes from the edit are submitted?
-
AuthorPosts
You must be logged in to reply to this topic.