activation of customer by sending link to his email using Suitelet Scripts - netsuite

Overview:
I create one custom customer form using Suitelet Script with fields like name,email,phone in GET Method and the values entered in this fields obtained in the POST Method by request.getParameter() method. the customer record is created is successfully but when clicking the submit button the customer record is to be "inactive" mode and the url link is to sent to the customer email address ,when he clicks the link his record is to be changed to"active" mode this must be with in same suitelet page.
My Requirement:
I created the customer record successfully with INACTIVE MODE and link this send the customer mail but i need how to make the customer record to ACTIVE MODE when he clicks the link and the result is to be viewed in same suitelet page.
I have Given my code Sample Below:
function getCustomerInfo(request, response){
if(request.getMethod() == 'GET'){
//CREATING THE CUSTOM FORM AND ADDING FIELDS IN THE FORM
var form = nlapiCreateForm('Custom Customer Form');
form.addField('sfg_company', 'text', 'Company Name').setMandatory(true);
form.addField('sfg_address1','text','Address1');
form.addField('sfg_address2','text','Address2');
form.addField('sfg_city','text','City');
form.addField('sfg_state','text','State');
form.addField('sfg_emailaddr','email','Email').setMandatory(true);
form.addField('sfg_phone','phone','Phone');
form.addSubmitButton('Submit');
response.writePage(form);
}else{
nlapiLogExecution('DEBUG','form',form);
// CREATING THE RECORD BY GETTING THE VALUES ENTERED IN THE CUSTOM FORM
var compName = request.getParameter('sfg_company');
var compAdd1 = request.getParameter('sfg_address1');
var compAdd2 = request.getParameter('sfg_address2');
var cities = request.getParameter('sfg_city');
var stateName =request.getParameter('sfg_state');
var email_addr = request.getParameter('sfg_emailaddr');
var phone_num = request.getParameter('sfg_phone');
var newCust = nlapiCreateRecord('customer');
newCust.setFieldValue('companyname', compName);
newCust.setLineItemValue('addressbook', 'addr1', 1, compAdd1);
newCust.setLineItemValue('addressbook', 'addr2', 1, compAdd2);
newCust.setLineItemValue('addressbook', 'city', 1, cities);
newCust.setLineItemValue('addressbook', 'state', 1, stateName);
newCust.setFieldValue('email', email_addr);
newCust.setFieldValue('phone', phone_num);
newCust.setFieldValue('subsidiary', 1);
newCust.setFieldValue('isinactive','T');
//sending activation link to the customer
var sender = nlapiGetUser();
var receiver = email_addr;
var subject = 'Customer Activation Link';
var recordId = nlapiGetRecordId();
var url = "https://system.na1.netsuite.com/app/common/entity/custjob.nl?id="+recordId+"&whence=";
var body = 'Dear Customer,Your Record is Created Successfully and it will activated by click the following link :'+ url;
nlapiSendEmail(sender,receiver,subject,body);
var id = nlapiSubmitRecord(newCust);
nlapiSetRedirectURL('RECORD','customer',id,null,false);
}
}

It sounds like what you basically want is to send out a confirmation link to a customer that they can click and complete some sort of registration.
If you want to re-use your suitele code then you need to pass a custom stage or action parameter that you can trigger different actions from. e.g.:
var stage = request.getParameter('custparam_action') || 'showForm';
switch(stage){
case 'showForm': doShowForm(request, response); break;
case 'validate' : doValidate(request, response); break;
}...
Then the url you need to send out needs to reference the suitelet rather than the customer page in Netsuite:
var ctx = nlapiGetContext();
var url = nlapiResolveURL('SUITELET', ctx.getScriptId(), ctx.getDeploymentId(), true) +"&custparam_action=validate"+ getSecureValidationParams());
the function getSecureValidationParams should create some sort of time sensitive parameters including a hashed key. If the request passes validation then you would show whatever other form you want to show or redirect to or show a thank you page.

function getCustomerInfo(request, response){
if(request.getParameter('custscript_sfg_custmer_param') != null){
var value = request.getParameter('custscript_sfg_custmer_param')
var loadRecord = nlapiLoadRecord('customer',value);
loadRecord.setFieldValue('isinactive','F');
loadRecord.setFieldValue('custentity_sfg_referredby',1);
nlapiSubmitRecord(loadRecord);
nlapiSetRedirectURL('RECORD','customer',value);
}
if(request.getParameter('custscript_sfg_custmer_param') == null){
if(request.getMethod() == 'GET'){
//CREATING THE CUSTOM FORM AND ADDING FIELDS IN THE FORM
var form = nlapiCreateForm('Custom Customer Form');
form.addField('sfg_company', 'text', 'Company Name').setMandatory(true);
form.addField('sfg_address1','text','Address1');
form.addField('sfg_address2','text','Address2');
form.addField('sfg_city','text','City');
form.addField('sfg_state','text','State');
form.addField('sfg_emailaddr','email','Email').setMandatory(true);
form.addField('sfg_phone','phone','Phone');
form.addSubmitButton('Submit');
response.writePage(form);
}
}
if(request.getMethod() == 'POST'){
nlapiLogExecution('DEBUG','form',form);
// CREATING THE RECORD BY GETTING THE VALUES ENTERED IN THE CUSTOM FORM
var compName = request.getParameter('sfg_company');
var compAdd1 = request.getParameter('sfg_address1');
var compAdd2 = request.getParameter('sfg_address2');
var cities = request.getParameter('sfg_city');
var stateName =request.getParameter('sfg_state');
var email_addr = request.getParameter('sfg_emailaddr');
var phone_num = request.getParameter('sfg_phone');
var newCust = nlapiCreateRecord('customer');
newCust.setFieldValue('companyname', compName);
newCust.setLineItemValue('addressbook', 'addr1', 1, compAdd1);
newCust.setLineItemValue('addressbook', 'addr2', 1, compAdd2);
newCust.setLineItemValue('addressbook', 'city', 1, cities);
newCust.setLineItemValue('addressbook', 'state', 1, stateName);
newCust.setFieldValue('email', email_addr);
newCust.setFieldValue('phone', phone_num);
newCust.setFieldValue('subsidiary', 1);
newCust.setFieldValue('isinactive','T');
//sending activation link to the customer
var sender = nlapiGetUser();
var receiver = email_addr;
var subject = 'Customer Activation Link';
var recordId = nlapiGetRecordId();
var webAddress = "https://system.na1.netsuite.com"
var scriptType = nlapiGetContext().getScriptId();
var scriptId = nlapiGetContext().getDeploymentId();
var location = nlapiResolveURL('SUITELET',scriptType,scriptId);
var id = nlapiSubmitRecord(newCust);
var link = webAddress+location+'&custscript_sfg_custmer_param='+id+"&whence=";
var url = 'Click Here ';
var body = 'Dear Customer,Your Record is Created Successfully and it will activated by click the following link :'+ url;
nlapiSendEmail(sender,receiver,subject,body);
nlapiSetRedirectURL('SUITELET',scriptType,scriptId);
}
The above code will Get Customer Information through external Suitelet form and saving the record in the system.

Related

How can I send image attachment to email

As I have created list of qr codes to scan and then I want to send this images to email by using Google app script.
current result
image is not sent to gmail.
codes
function sendEmail(sheetName = "emails") {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName).activate();
var spreedsheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lastRow = spreedsheet.getLastRow();
//var ssa = SpreadSheetApp().getSheetByName(sheetName); // spread sheet object
const messageBody = "Dear receiver, We would like to invite you on upcoming seminar please use this link {actual link} and show receiptionis this bar code {actual code}"
const subjectText = "Seminar invitation"
// loop rows or spread sheet
for (var i=2; i<= lastRow; i++) {
var receiverName = spreedsheet.getRange(i, 1).getValue();
var receiverEmail = spreedsheet.getRange(i, 2).getValue();
var seminarLink = spreedsheet.getRange(i, 3).getValue();
var barcode = spreedsheet.getRange(i, 4).getBlob();
var msgBdy = messageBody.replace("receiver",receiverName).replace("{actual link}", seminarLink);
var photoBlob = barcode
MailApp.sendEmail({
to: receiverEmail,
subject: subjectText,
htmlBody: messageBody + "<br /><img src='cid:qrCode'>",
inlineImages: { qrCode: photoBlob }
});
}
}
From your following reply,
images are created from =IMAGE("chart.googleapis.com/…) with that google sheet excel
In this case, I thought that your goal can be achieved using Google Apps Script.
When I saw your script, getValue() is used in a loop. In this case, the process cost will become high. In this modification, this issue is also modified.
Modified script:
function sendEmail(sheetName = "emails") {
var spreedsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var lastRow = spreedsheet.getLastRow();
const messageBody = "Dear receiver, We would like to invite you on upcoming seminar please use this link {actual link} and show receiptionis this bar code {actual code}";
const subjectText = "Seminar invitation";
const range = spreedsheet.getRange("A2:D" + lastRow);
const values = range.getValues();
const formulas = range.getFormulas();
values.forEach(([receiverName, receiverEmail, seminarLink], i) => {
const url = formulas[i][3].split('"')[1];
const photoBlob = UrlFetchApp.fetch(url).getBlob();
var msgBdy = messageBody.replace("receiver", receiverName).replace("{actual link}", seminarLink);
MailApp.sendEmail({
to: receiverEmail,
subject: subjectText,
htmlBody: messageBody + "<br /><img src='cid:qrCode'>",
inlineImages: { qrCode: photoBlob }
});
});
}
When this script is run, the values are retrieved from "A2:D" of the sheet. And, each value is retrieved from each row. In the case of the column "D", the URL is retrieved from the formula, and the image blob is retrieved using UrlFetchApp. And, those values are put as the email.
References
forEach()
fetch(url, params)
Update 2
As said in the comments, replace this line:
var barcode = spreedsheet.getRange(i, 4).getBlob();
To:
var barcode = UrlFetchApp.fetch(spreedsheet.getRange(i, 4).getFormula().match(/\"(.*?)\"/)[1]).getAs('image/png')
Update
As you are inserting the image via a IMAGE Formula, you can easily parse the value, obtain the URL and get the Blob via UrlFetchApp
Sample:
const sS = SpreadsheetApp.getActive()
function testSendImage() {
const img = sS.getRange('A1').getFormula()
const urlImg = img.match(/\"(.*?)\"/)[1]
const fetchImage = UrlFetchApp.fetch(urlImg).getAs('image/png')
MailApp.sendEmail({
to: "some#gmail.com",
subject: "QR",
htmlBody: 'Check this QR <img src="cid:fetchImage" />',
inlineImages: { fetchImage: fetchImage } })
}
In the current state, there is no method for extrancting the image from a cell, however there is a Feature Request on Google's Issue Tracker, you can click here to review it.
Remember to click in the top right if you want this feature to be implemented.
In any case, you review this StackOverflow question for workarounds or alternative methods.

sending Email with Attachment xpages

this is my sample coding for sending email with attachment. The content of word is not send correctly.
attachment is using "file upload"
// write mail
var setdoc:NotesDocument = database.getProfileDocument("System Setting", "");
var server = setdoc.getItemValueString("MailDBSvr");
var dname = setdoc.getItemValueString("MailDbPath");
var web = setdoc.getItemValueString("InternetAddress");
var maildoc:NotesDocument = database.createDocument();
maildoc.replaceItemValue("Form", "Memo");
maildoc.replaceItemValue("Subject","Test Send Mail");
session.setConvertMime(false);
var stream = session.createStream();
stream.writeText("<html><body>");
stream.writeText("<p>Dear " + "[person]" + ",</p>");
stream.writeText("<p>Attached item is an image of </p>");
stream.writeText("<p> ***THIS IS AN AUTOMATED MESSAGE - PLEASE DO NOT REPLY DIRECTLY TO THIS EMAIL***</p>");
stream.writeText("</body></html>");
var body = maildoc.createMIMEEntity("Body");
var Att= document1.getDocument(true).getFirstItem("Attachment");
maildoc.copyItem(Att,"Body") // try adding an item
body.setContentFromText(stream, "text/html;charset=UTF-8", 1725);
stream.close();
maildoc.closeMIMEEntities(true);
session.setConvertMime(true);
maildoc.replaceItemValue("SendTo","TestUser1#devsvr1.pcs.com.my");
maildoc.send();
The result come out is only the attachment field without any text value inside. I not sure which part of it is wrong.
sample Result screen:
Recommended Mime style
var HTMLMail = function() {
...
}
var mail = new HTMLMail();
mail.setTo("TestUser1#devsvr1.pcs.com.my")
//mail.addFileAttachment(result);
mail.setSubject("Test Send Mail");
mail.addHTML("<h1>Hi!</h1>");
mail.addHTML("<table><tbody><tr><td>contents in a table here</td></tr></tbody></table>");
mail.send();
IBM Notes/Domino has 2 ways to show 'pretty words and pictures'
RichText
MIME
You should only use one or the other, but here you are actually mixing both the different types.
Above, when you copy the Attachment Item, you are actually adding the first 'Body' item, you can see it's type 'RichText'.
Then we you createMimeEntity you are creating the second 'Body' item, and it's type is 'MimePart' (it is probably showing second because the Mime is not applied until CloseMimeEntities)
So now you have 2 Body items with different parts. You are seeing the 'RichText' attachment in Notes because it is first listed item.
What you actually need to do is create the correct multipart mime structure.
If you want a bit more information about mime, I a blog post on my site which explains it a little bit more, including some info about the correct mime structure.
http://camerongregor.com/2016/04/21/webmail-ui-you-must-learn-about-mime/
If you haven't seen it yet there is an XSnippet by Mark Leusink which has a demo of creating a mime email using SSJS. I don't use this myself as I don't use SSJS but it might be useful to you as it should handle most of this mime manipulation for you.
https://openntf.org/XSnippets.nsf/snippet.xsp?id=create-html-mails-in-ssjs-using-mime
My coding with reference using rich-text style :
var setdoc:NotesDocument = database.getProfileDocument("System Setting", "");
var server = setdoc.getItemValueString("MailDBSvr");
var dname = setdoc.getItemValueString("MailDbPath");
var web = setdoc.getItemValueString("InternetAddress");
var maildoc:NotesDocument = database.createDocument();
maildoc.replaceItemValue("Form", "Memo");
maildoc.replaceItemValue("Subject","Test Send Mail");
session.setConvertMime(false);
var stream = session.createStream();
stream.writeText("<html><body>");
stream.writeText("<p>Dear <b>" + "person" + "</b>,</p>");
stream.writeText("<p> ***THIS IS AN AUTOMATED MESSAGE - PLEASE DO NOT REPLY DIRECTLY TO THIS EMAIL***</p>");
stream.writeText("</body></html>");
var tmpDoc:NotesDocument = maildoc.getParentDatabase().createDocument();
var mime:NotesMIMEEntity = tmpDoc.createMIMEEntity("myBody");
var addRt:NotesMIMEEntity = maildoc.getMIMEEntity("addBody");
var Att:NotesRichTextItem = document1.getDocument(true).getFirstItem("Attachment");
if(addRt != null && #Length(addRt.getContentAsText().trim()) > 28) {
stream.writeText('<font size="2" face="sans-serif">'); // Enforce "simiilar" font type/size...
stream.writeText(addRt.getContentAsText());
stream.writeText('</font>');
}
mime.setContentFromText(stream, "text/html", NotesMIMEEntity.ENC_NONE);
var prevMime = session.isConvertMime();
session.setConvertMime(true);
tmpDoc.closeMIMEEntities(true,"myBody");
var rt:NotesRichTextItem = maildoc.getFirstItem("Body");
var body = null;
if (rt != null) {
body = rt.copyItemToDocument(tmpDoc,"Body");
rt.remove();
}
rt = maildoc.createRichTextItem("Body");
var rtMime:NotesRichTextItem = tmpDoc.getFirstItem("myBody");
rt.appendRTItem(rtMime);
if(Att != null) {
if(addRt == null) rt.addNewLine(1);
rt.appendRTItem(Att);
Att.remove();
}
if(body != null) {
rt.addNewLine(2);
rt.appendRTItem(body);
}
if(addRt != null) {
addRt.remove();
addRt.recycle();
}
stream.close();
maildoc.closeMIMEEntities(true);
session.setConvertMime(true);
maildoc.replaceItemValue("SendTo","TestUser1#devsvr1.pcs.com.my");
maildoc.send();

How to get all subsidiaries showing in UI by RESTlet in Netsuite?

i could get all names, types, labels and available options for fields except subsidiary.
There are two options for subsidiary in Netsuite UI. But when i try to get by code, i could get only one subsidiary which was referred in Employee creation.
This is the code snippet.
function getFields(datain) {
var record = nlapiCreateRecord ( datain . recordtype );
var fields = record.getAllFields();
var requiredFields = {};
fields.forEach(function(fieldName){
var field = record.getField(fieldName);
if(field.mandatory === true) {
var id = field.getName();
var field_details = {}
field_details['Type'] = field.getType();
field_details['Label'] = field.getLabel();
if(field.getType() == 'select' || field.getType() == 'multiselect') {
var Options = field.getSelectOptions();
var selectOptions = {};
for(var i in Options) {
var opt_id = Options[i].getId();
selectOptions[opt_id] = Options[i].getText()
}
field_details['Options'] = selectOptions;
}
requiredFields[id]=field_details;
}
});
return requiredFields;
}
How to get all subsidiaries available in lead , customer or contact creation?
Subsidiaries are retrieved based on subsidiaries set in roles not on employee creation. Here before i have selected only one subsidiary in role.
If we select all subsidiaries for the appropriate role, we can get all subsidiaries which were selected in the role.

How to create Purchase Order in Netsuite with ScriptSuite?

I am new to Netsuite and I was asked to perform a script that was launched from an application programmed in java. The script with a function to generate a Purchase Order in Netsuite and other function to list the Purchase Order created earlier. It turns out that for this I am using the api SuiteScript but when creating the Purchase Order run the java application and launches the script but it gives the following error:
Aug 03, 2015 2:49:00 PM com.gargoylesoftware.htmlunit.WebClient printContentIfNecessary
INFO: {"error": {"code": "user_error", "message": "Please enter value (s) for: Vendor"}}
Javascript function to create is:
function CreatePurchase_Orders(datain){
var output = '';
nlapiLogExecution('DEBUG','createRecord','ingreso la consulta' ) ;
nlapiLogExecution('DEBUG','createRecord', 'Ingresa: '+ datain);
//var msg = validateTimeBills(datain);
var msg = null;
if (msg){
var err = new Object();
err.status = "failed";
err.message= msg;
return err;
}
var Purchase_Orders = datain.Purchase_Order;
nlapiLogExecution('DEBUG','createRecord', 'obtuvo el objeto: '+ Purchase_Orders);
for (var Purchase_Orderobject in Purchase_Orders){
var Purchase_Order = Purchase_Orders[Purchase_Orderobject];
var transdate = Purchase_Order.Transdate;
var Form = Purchase_Order.Form;
var Vendor = Purchase_Order.Vendor;
var Currency = Purchase_Order.Currency;
var Item = Purchase_Order.Item;
nlapiLogExecution('DEBUG','campos','transdate: '+ transdate+'/Form: '+Form + ' /Vendor: ' + Vendor + ' /Currency: ' + Currency
+ ' /Item: ' + Item);
var Purchase_Order = nlapiCreateRecord('purchaseorder');
var nlobjAssistant = nlapiCreateAssistant ( 'asistente' , false ) ;
var Purchase_Orderid = 1;//nlapiSubmitRecord( Purchase_Order , true, true);
if(Purchase_Order){
nlapiLogExecution('DEBUG', 'Purchase_Order ' + Purchase_Orderid + ' successfully created', '');
nlapiLogExecution('DEBUG', 'createRecord', 'creo el record');
}
Purchase_Order.setFieldValue('transdate', transdate);
Purchase_Order.setFieldValue('inpt_customform1', Form);
Purchase_Order.setFieldValue('vendor', Vendor);
Purchase_Order.setFieldValue('inpt_currency7', Currency);
Purchase_Order.setFieldValue('inpt_item', Item);
Purchase_Order.setFieldText('quantity_formattedValue', '1');
Purchase_Order.setFieldText('rate_formattedValue', '1');
Purchase_Order.setFieldText('amount_formattedValue', '1');
Purchase_Order.setFieldText('inpt_taxcode', 'VAT_MX:UNDEF_MX');
Purchase_Order.setFieldText('grossamt_formattedValue', '1');
Purchase_Order.setFieldText('tax1amt_formattedValue', '0');
Purchase_Order.setFieldText('expectedreceiptdate', '24/6/2015');
//var Purchase_Orderid = 1;//nlapiSubmitRecord( Purchase_Order , true, true);
var submitRecord = nlapiSubmitRecord(Purchase_Order);//,true);
nlapiLogExecution('DEBUG', 'submirRecord ' + submitRecord);
}
var mesg = new Object();
mesg.status = "OK";
mesg.message= nlobjAssistant.getAllFields();
return mesg;
}
And the function code in Java is:
WebClient client = new WebClient(BrowserVersion.FIREFOX_31);
client.getOptions().setJavaScriptEnabled(false);
client.getOptions().setThrowExceptionOnScriptError(false);
WebRequest requestSettings = new WebRequest(new URL(url),HttpMethod.POST);
requestSettings.setAdditionalHeader("Host", "rest.na1.netsuite.com");
requestSettings.setAdditionalHeader("User-Agent", "SuiteScript-Call");
requestSettings.setAdditionalHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
requestSettings.setAdditionalHeader("Accept-Language", " es-cl,es;q=0.8,en-us;q=0.5,en;q=0.3");
requestSettings.setAdditionalHeader("Accept-Encoding", "gzip, deflate");
requestSettings.setAdditionalHeader("Content-Type", "application/json");
requestSettings.setAdditionalHeader("Pragma", "no-cache");
requestSettings.setAdditionalHeader("Cache-Control", "no-cache");
requestSettings.setAdditionalHeader("Referer", "http://localhost:8084");
requestSettings.setAdditionalHeader("Cookie", "");
requestSettings.setAdditionalHeader("Connection", "keep-alive");
requestSettings.setAdditionalHeader("Authorization", "NLAuth nlauth_account=" + account + ", nlauth_email=" + mail + ", nlauth_signature=" + pass + ", nlauth_role=" + role + "");
Gson gson = new Gson();
//objeto llenado estaticamente de forma momentanea, se debe leer desde archivo externo
Purchase_Order purchaseOrder = new Purchase_Order("25/06/2015","formTest","vendorTest","CurrencyTest","itemTest");
String cuerpo = gson.toJson(purchaseOrder);
System.out.println(cuerpo);
// Set the request parameters
requestSettings.setRequestBody(cuerpo);
Page page = client.getPage(requestSettings);
WebResponse response = page.getWebResponse();
String json = response.getContentAsString();
System.out.println(json);
With this javascript function you should create me a record Purchase Order but I can not find the error and the solution if someone could please help me I would appreciate it a lot.
PS: if you have to create a customized form could tell me how?
thanks!
Here are some points :
As your error message says Please enter value (s) for: Vendor, you're missing the value for vendor field, which is mandatory. In your piece of code you're passing wrong internalid value for vendor. You should use entity instead of vendor
Purchase_Order.setFieldValue('entity', Vendor); // where vendor is the internal id of the vendor record
For setting custom form you can use
Purchase_Order.setFieldValue('customform', Form); // where Form is the id of the custom form
I also noticed that you're setting some values in purchase order which I suspect are to be a kind of custom one. If that is the case, then your custom field internal id should be prefixed with custbody.
For all the standard fields internal id you can refer to the Suite script Records Browser.

How Do I get a page's URL using JSOM

I am using SharePoint 2013 workflow.
I am in the Initiation form when my my users clock the Start button to start the workflow.
I am using JSOM to start the workflow but since I am on the Initiation form, I don't know the URL of the page. I do know the list (pages) and the the list id (2).
Can someone help me retrieve the list id's url using JSOM?
Thanks
Tom
How to get Page Url in Initiation Form page:
var listId = getParameterByName('List');
var itemId = getParameterByName('ID');
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
var list = web.get_lists().getById(listId);
var listItem = list.getItemById(itemId);
ctx.load(listItem);
ctx.executeQueryAsync(
function () {
var itemUrl = listItem.get_item('FileRef');
console.log(itemUrl);
},
function (sender, args) {
console.log(args.get_message());
}
);
,where
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
is intended for retrieving parameter from query string
Source

Resources