I have a button that was added to a form via UserE...
# suitescript
j
I have a button that was added to a form via UserEvent script. The button calls a Client Script function when pressed. Inside that Client Script function I would like to open, in a new window, a Suitelet, which has accepted via POST, some data from the calling function. This data is too long to go in the URL. I originally tried with url.resolveScript and passing my data in the params but it gets appended to the URL instead. Any suggestions?
k
Use N/https
then you can call the https.post() function
to the suitelet
j
But if i want to open it in a new window?
Copy code
Then use <http://https.post|https.post> then put your json in the body then the suitelet invoked will put that json data into the runtime session. Key value pair stored is available in server to server only. Then after invoking the first suitelet. You can now call another suitelet then get the key value pair stored in the runtime session.
basically I want the Suitelet to open in a new window as if it posted to itself (except instead of coming from itself, it came from the record that had the button on it)
k
Have the button save data to a custom record, then send the custom record ID to the get request to the new window?
j
could do, but probably not worth it for this use case
c
@jen Can you use window.open to open a new window, add a form to it with the data you want to send and the Suitelet URL as the action, then submit it?
j
that doesn’t really solve the issue as I still can’t get the data from the original record to the new window
b
you need to make a new form element to make that post that you will programmatically submit, with an appropriate target
👍 2
c
☝️ this is what I was trying to say 😄
j
yeah, that’s what I’m thinking. Embed my button in a <form> where the action is my suitelet url.
I won’t use form.addButton I’ll just add a button to my DOM another way
😉
Success
👍 1
Copy code
let script_id = 513;
    	let deployment_id = 1;

    	let suitelet = url.resolveScript({scriptId: script_id, deploymentId: deployment_id});

    	// Check if form already exists, if it does, we don't need to add it again, we only need to update the textarea contents.
    	if(jQuery('#custscript_document_xml').length) {

    		jQuery('#custscript_document_xml').val(text);

		} else {

    		document.body.innerHTML += `<form id="textxmlform" action="` + suitelet + `" method="post" target="_blank"><textarea id="custscript_document_xml" name="custscript_document_xml">` + text + `</textarea></form>`;

		}

		jQuery('#textxmlform').submit();