Hi, I am trying to redirect the record to a specif...
# suitescript
t
Hi, I am trying to redirect the record to a specific form when criteria are met. I am using below script but upon doing so, it keeps on loading and end up not redirecting to that form. I am calling this on UE beforeLoad
redirect.toRecord({
*type*: 'customrecord_xxx',
*id*: context.*newRecord*.*id*,
*parameters*: {'cf':'1806'},
*isEditMode*: context.*type* == 'edit' ? *true* : *false*
});
In addition, it says ERR_TOO_MANY_REDIRECTS
d
does the criteria you mention exclude beforeLoad events where the form is already
1806
?
a
... I must be missing something? You're trying to set a specific custom form before record load, and you're doing this when criteria are met... on the record that is loading?
why wait till record load? if you know the criteria just mass update and set the custom form on the records?
t
yes my criteria is
*const* isScopeToolRecord = context.*newRecord*.getValue({*fieldId*: cfg.*DEAL*.*SCOPE_TOOL*}); // this should be true
const isTheForm = customForm == 1234 // this should be true as well
@Anthony OConnor the custom record has 2 types of A) Tag as scope tool and B) that isn't tag as scope tool.
Record should have their own form based on that
a
gotcha so you dont want to actually set the form on the record, you just want the ui to use it?
thumbs up 1
t
yes correct
a
if you set the form and they save it tho won't it save the new form?
I feel like you probably want to do this in a client page init?
t
Nope, the custom record has the "preferred" record. Therefore, it uses other form to default sad parrot
a
you can actually make a form specific client script if there's logic based on which form is in use... not sure that wins you anything without knowing the bigger picture
t
Well, on client page init. The record should have to load before it redirects. I am thinking a possibility there the page should redirect before it actually load 🤔
a
... right... it isn't working though 😂
d
client script doesn't trigger on view either
a
I'm not suggesting a redirect btw.. I was suggesting just setting the customform value
d
so, does your redirection logic have a check to exclude if the current form is already
1806
?
surely without that it would endlessly redirect
a
yeah i think David is on to something there
t
const isScopeToolRecord = context.newRecord.getValue({fieldId: cfg.DEAL.SCOPE_TOOL}); // this should be true
const customForm = context.newRecord.getValue({fieldId: cfg.CUSTOM_FORM});
const isTheForm = customForm == 1234 // this should be true as well
if(isScopeToolRecord && isTheForm) {
redirect.toRecord({
type: 'customrecord_xxx',
id: context.newRecord.id,
parameters: {'cf':'1806'},
isEditMode: context.type == 'edit' ? true : false
});
}
this is the entire code on load
a
umm what is
customForm
?
☝️ 1
t
sorry, its the current form of the record when it load
a
ok but that will still be 1234 after the redirect right?
🤔 1
are you setting cfg.CUSTOM_FORM at some point?
d
that'll be a constant with value
customform
at a guess
a
right (hate that) 🙂
d
potentially you'll need to pull the form parameter from the url on beforeLoad
t
yes they are constant value.. so if the custom form is 1234 and isScopeToolRecord is true,, record should be redirected other form
a
but if you load a record on redirect with a specific form what is the form value? the one you set on redirect? or the one stored with the record?
t
the one set on the redirect
a
i would log customForm to confirm that
d
going to test that
t
ok.. will try it as well
d
just testing with the console, I'm getting
undefined
when trying to get the custom form value *_when in view mode_
a
umm so how does the parameter stuff work? cos it looks like it will just put that as a URL param on the record url that gets created... https://ACCTNUM.netsuite.com/blah/blah/blah/....?id=22334455&cf=1806 .. that's not gonna set the form to 1806
d
yeah, it works for me
a
huh really there's a cf param that just works for all records? dont think i ever knew that
d
in view or edit, setting the
cf
url param correctly loads the record with that form
a
cool TIL
t
i guess I need to use this
context.*request*.*parameters*.*cf*
👍 1
a
to determine if you already redirected?
d
oh, in testing, if you're in edit mode, you can successfully get the
customform
value from newrecord
t
David, I think its because its not yet load on "VIEW" mode that's why its not working before.. So I guess.. I need to determine the form use the other way which is can be
context.*request*.*parameters*.*cf*
d
why doesn't
context.form
have an
id
property?....
t
yes Anthony, and what is the current form use 🤔
oh? I haven't try that yet David.. Let me test it
d
the docs say it doesn't have the id
also I tested getting the customform in view mode on an already loaded page. So I think it's just that customform isn't exposed while in view mode (which is what I see in the UI too)
t
ill try to explore the exectionContext 🤔 maybe there is something there 😅
b
you havent shared enough code, but dont make the mistake of creating an infinie loop of redirects
your beforeLoad triggers another beforeLoad
d
@battk the code problem was that you can't
context.newRecord.getValue
the 'customform' field in view mode (returns undefined). solution was to check
context.request.parameters
for the
cf
param set during the redirect and not redirect again
t
I think I found the solution on this. I use redirect.redirect instead then I use customForm to validate if the form is already what I wanted. And also use this to omit the looping on beforeLoad that produce the error ERR_TOO_MANY_REDIRECTS
const customForm = <http://context.request.parameters.cf|context.request.parameters.cf>;
const isScopeToolRecord = context.newRecord.getValue({fieldId: cfg.DEAL.SCOPE_TOOL});
const url = context.request.url + '?rectype=' + 5176 + '&id=' + context.newRecord.id + '&cf=' + cfg.FORMS.SCOPE_TOOL;
log.debug('url', url)
if(customForm != cfg.FORMS.SCOPE_TOOL && isScopeToolRecord) {
redirect.redirect({
url: context.request.url + '?rectype=' + 5176 +
'&id=' + context.newRecord.id + '&cf=' + cfg.FORMS.SCOPE_TOOL
});
}
thank you all for the comments 🙂