<@U88N132LS> Hi Vaid . I tried your solution , url...
# suitescript
s
@Vaid Hi Vaid . I tried your solution , url query param worked right out of the box . But the 2nd approach of setting form field value almost worked . Able to set the value of the form field . But when i am trying to get the value using below code its not getting that value :
Copy code
var params = option.request.parameters;
				log.debug('params',params);
				log.debug('params.custpage_accesstoken',params.custpage_accesstoken);
 			 if((params!= null && params!= undefined && params!='') &&
 					 (params.custpage_accesstoken!= null && params.custpage_accesstoken!= undefined && params.custpage_accesstoken!='')){
 				
				 log.debug('Access Token value received from client script is -> ',params.custpage_accesstoken);
 				 
 			 }
As i added a normal button instead of submit button , is it failing ? Please advice
v
option is your context ?
s
yes correct
in client script i am using below code :
Copy code
currentRecord.get().setValue({fieldId: 'custpage_accesstoken', value:accessToken});
I created hidden field like below in suitelet
Copy code
var accessToken = token_form.addField({
						id : 'custpage_accesstoken',
						type : ui.FieldType.LONGTEXT,
						label : 'Hidden field'
					}).updateDisplayType({
						displayType : ui.FieldDisplayType.DISABLED
					});
v
function onRequest(option) { try { var params = option.request.parameters; //this should give you values for your fields --- are you sure you're accessing this after form post ? } catch(e) { // }
s
I added this condition like u suggested .
Copy code
if(option.request.method == 'POST')
            {}
but its not going inside it even thought i clicked the button . so i removed it temporarily
v
In this case user will need to press the submit button after getting the token
s
yeah , but here we need to click button like this instead of submit button , because i used submit button for other purpose
Copy code
token_form.addButton({
						id : 'custpage_refresh_token',
						label : 'Refresh Token',
						functionName : 'getAccessTokenFromRefreshToken'
					});
v
That's fine , but once you set the field -- you can access the values only after doing a POST
s
oh . any advice in this case ?
v
Yes, either reload the screen or split your logic so that any functionality that runs on that field value happens on the form submission
If there is anything else running on submit - you can add a custom button for that too, but page reload should be fine
s
Thank you , i will try to do like that
v
@samantha Its not the usual route but : If you don't want to add your returned value as the url param, you can still store the value in a text file(filecabinet) or a custom record & reload the screen, (but add the url param like: &custparam_tokenpresent=true in the window.open url. Now on page reload, you can similarly check if(options.request.parameters.custparam_tokenpresent) file.load({id: ''}).getContents() // to get back the value you stored earlier in this file
s
Thats a great approach , u never run out of ideas . thanks
🙂 1
👍 1