Simple question. i saw this sample Suitelet script...
# suitescript
m
Simple question. i saw this sample Suitelet script to create a survey form. I tested and it displays fine. But how do you use this? If I click submit i know it doesn’t do anything, but how would you connect this to a survey record and capture it? https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/article_165210654666.html#Create-a-Custom-Survey-Form
a
you need to seperate the code into two distinct pieces. based on the
context.request.method
The piece you have already should all be wrapped in a
GET
conditional
if (context.request.method === 'GET') {
***paste evernthing from your link***
}
Then you need a section to handle the incoming form data when they click submit, clicking "submit" is a
POST
rather than a
GET
if (context.request.method === 'POST') { *add your new coder here* }
Probably easier to look at this one to get the idea https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/article_159022995775.html#Write-and-Send-Email
m
Oh! So that code is nested in a Get request, then you use a Post to add these values to say a new survey record like record.create.
a
exactly
m
🙏
a
a common pattern you see is a separate function for the method handler, and then dedicated functions for each request method so you end up with something like
Copy code
function onRequest(context){
    if (context.request.method === 'GET') {
        onGet(context);
    }
    if (context.request.method === 'POST'){
        onPost(context);
    }
}

function onGet(context){
    //do the GET things
}

function onPost(context){
    //do the POST things
}

return{onRequest};
m
That makes complete sense now….Cheers!
👍 1