I am using url.resolveRecord to navigate to a new ...
# suitescript
n
I am using url.resolveRecord to navigate to a new support case from an existing one to basically "make a copy" and display in edit mode so they can modify fields before saving. However, when you save it just redirects back to the record I initially came from instead of showing the new record I created. How would you handle getting to the newly created record after save?
m
When you save the new record it will return the ID of the record that you created. You need to pass that into
url.resolveRecord
.
n
@Marvin here is the code, on button click of ServiceEvent#1, it opens a new service event with that parameter. It uses that id to default the fields based on the values from ServiceEvent#1. When I save this new service event instead of redirecting to ServiceEvent#2 it goes back to ServiceEvent#1
Copy code
window.location = url.resolveRecord({
                        recordType: 'supportcase',
                        isEditMode: true,
                        params: {
                            servicecopy : copyfromid
                        }
                    })
m
Look at the help topic on
url.resolveRecord
you are missing a required parameter
recordId
.
n
Can I use url.resovleRecord on a saveRecord function in Client Script? Cause I tried and tried to pass context.newRecord.id to the recordId parameter and it just opened a blank service event in a new tab
m
This is the pattern that you should have.
Copy code
var newrecord = record.copy({...});
// set fields on new record
var new_recordid = newrecord.save();
window.location = url.resolveRecord({
...
recordId: new_recordid
});
n
They want to set more fields or adjust existing copied fields before saving
m
Yeah just do that before saving it.
n
Sorry, may not be clear. They as the user wants to click copy, open a new record with defaulted fields in the UI, manipulate fields and then click save themselves
got it working with a redirect.toRecord on the afterSubmit. Thanks
m
Oh yeah I misunderstood what you were trying to do.
n
I probably explained poorly as well and not sure why i didn't think of that sooner. but thanks!