I created a UE script that adds a button and loads in a CS script. The CS script in turn calls a SL script when the button is clicked.
I deployed the suitelet script to be executed as the administrator role with every role also being part of the audience.
My CS script:
https.post.promise({
url: "https://"+domain+".app.netsuite.com/app/site/hosting/scriptlet.nl?script=687&deploy=1",
body: params
})
.then(function (response){
log.debug({title: 'Response',details: response});
console.log('response', response);
})
The result I get is HTML telling me I have to login to access the page. When I actually take the URL and paste it myself in the browser however, it does work. Does anyone know why this happens?
I don't know much about https.post.promise method but even I once faced this exact error.
My suggestion here would be to use url.resolveScript method in your ClinetScript that would apparently call your Suitelet Script.
window.onbeforeunload = null;
var suiteletURL = url.resolveScript({
scriptId: 'SUITELET SCRIPT ID HERE',
deploymentId: 'SUITELET DEPLOYMENT ID HERE',
params: {
//If any
}
});
window.open(suiteletURL, '_self', false);
Let me know in case of any issue in the comments below.
It seems the problem was that Netsuite generated an external URL which required authentication always. The following code solved my issue:
var suitletURL = url.resolveScript({
scriptId: 'scriptid',
deploymentId: 'deploymentid',
returnExternalUrl: false
});
Related
I'm trying to using Airtable, node.js, express.js and jquery to create a simple user authentication functionality but I'm fairly new at this and I'm running into a problem I can't seem to fix and the articles I've read I can't seem to grasp or adapt to my particular situation.
I have this Ajax call in my html doc:
$("#checkUser").submit(function(e) {
var studentID = $('input[name="student"]').val()
e.preventDefault(); // avoid to execute the actual submit of the form.
var form = $(this);
var url = form.attr('action');
$.ajax({
type: "POST",
url: url,
data: form.serialize(), // serializes the form's elements.
success: function(data) {
$(window).attr("location", window.location.href + 'Dashboard?student=' + studentID);
},
error: function(data){
console.log("User not found. Try again");
}
});
});
This call sends the inputted username and data to the server which then processes it in the following way:
app.post('/checkUser', urlencodedParser, function(request,response){
var user = JSON.stringify(request.body);
user = JSON.parse(user);
base('RegisteredStudents').select({
filterByFormula: '{UserID} = ' + user.student,
view: "Grid view"
}).eachPage(function page(records, fetchNextPage) {
records.forEach(function(record) {
response.sendStatus(200);
});
fetchNextPage();
}, function done(error) {
response.sendStatus(404);
});
});
If the user exists in the database of Airtable, it should send '200' which the Ajax then reacts by redirecting accordingly to the user's profile. Otherwise, if the user does not exist, the server should respond with '404', which the Ajax call should react to by printing a statement in the console. While it does do these two things well, the server breaks down when, after a student puts in the wrong user ID and the Ajax prints the statement, the student tries to put once more a userID. I get the " Can't set headers after they are sent. " message. Please, how can I solve this?
Thank you!
You have two response.send..., you can only send data once. Either make sure only one runs with some conditional or add return before all response.send... so if any of them runs, the program will return and the other response.send.. will not run.
I have a script that changes the default for the email you can create in a record of the field Include Transaction.
What I cannot figure it out is where to deploy the script.
The url for the email pop up is https://xxxxxx-sb1.app.netsuite.com/app/crm/common/crmmessage.nl?transaction=356724&entity=25778&l=T&templatetype=EMAIL
My script is:
function pageInit(type) {
nlapiSetFieldValue('includetransaction', 'F');
}
I tried transaction and email template but it did not work.
Thanks for any help.
You cannot deploy a client script to the Message record.
A workaround is to use a User Event script that "injects" the code in a custom html field that will be run client side.
function beforeLoad(type, form, request) {
var script = "<script> nlapiSetFieldValue('includetransaction', 'F'); </script>";
form
.addField('custpage_client_script', 'inlinehtml', 'Client Script')
.setDefaultValue(script);
}
Deploying a User Event script to "Message" as the Before Load function works, using the following:
function beforeLoad(type)
{
nlapiSetFieldValue('includetransaction', null, null, false);
}
I an new to NetSuite, and I am having a problem. I have created a button on a form through a user event script.
The button calls a client script, which executes a saved search. The search result should be displayed to the user.
Everything is located in one file:
function userEventBeforeLoad_AddSearchButton(type, form, request){
if(type == 'view' || type == 'edit'){
form.setScript('customscript_tvg_project_search_button');
var projectid = nlapiGetFieldValue('companyname');
form.addButton("custpage_search", "KHM Search", "performSearch('" + projectid + "')");
}
}
function performSearch(projectid) {
console.log('test in client');
alert('projectid = ' + projectid);
var obj = nlapiLoadSearch(null, 'customsearch_project_cost_detail_sublist');
obj.setRedirectURLToSearchResults();
}
I created a user event script record for userEventBeforeLoad_AddSearchButton(). and a client script record for performSearch().
In the code above, the button is created and the alert is being displayed. But no redirect is happening.
When I look at the result in Firebug it looks like this:
{"result":"\/app\/common\/search\/searchresults.nl?api=T","id":5}
Any ideas why the redirect is not happening, and what to do?
Edit: My code above was stripped down to simplify. The reason I am passing projectid over is that I actually need to filter the search result, suing the following two lines:
var searchFilter = new nlobjSearchFilter('job', null, 'anyof', projectid);
obj.addFilter(searchFilter)
Although the documentation does state that, "This method is supported in afterSubmit user event scripts, Suitelets, and client scripts", it seems from this NS User Group post by a Netsuite Employee in reply to someone who experienced the same issue as you, that the API does not actually perform the redirection client side:
Redirection works on server side. Use window.location.assign(url) to
navigate via script in client-side.
Testing this, I can see that setRedirectURLToSearchResults does appear to correctly "load the search into the session", so adding this line afterwards should fix your problem.
window.location = '/app/common/search/searchresults.nl?api=T';
setRedirectURLToSearchResults is not working for me either, but since you are using clientscript you might want to try this:
function performSearch(projectid) {
console.log('test in client');
alert('projectid = ' + projectid);
var searchid = 'customsearch_project_cost_detail_sublist';
location = '/app/common/search/searchresults.nl?searchid=' + searchid;
}
I'm trying post a message as admin of a facebook page, but my code keeps posting as my personal account to the "wall" of the page, not as the page itself.
When authorizing my application I ask for the right permissionscopes, and accept them. Although, when I check my permissions with /{USER-ID}/permissions, it says that I've denied the application to manage my pages. Any ideas why?
Here's my code for posting:
var parameters = {};
parameters.message = "Hello world, this is dog.";
parameters.access_token = req.session.access_token;
FB.api('{PAGE-ID}/feed', 'post', parameters, function (result) {
if (!result) {
return res.send(500, 'error');
} else if (result.error) {
if (result.error.type == 'OAuthException') {
result.redirectUri = FB.getLoginUrl({ scope: 'publish_actions,manage_pages,publish_pages', state: encodeURIComponent(JSON.stringify(parameters)) });
}
console.log(result);
return res.send(500, result);
}
res.send(result);
});
And yes, of course I use my page id instead of the placeholder in my code above.
*Update: It seems like the permissions aren't even asked for when authorizing the application. I added the email scope to the list and it appears when I re-authorize the application.
Could this have anything to do with my application not beeing approved?
"Submit for Login Review
Some of the permissions below have not been approved for use by Facebook.
Submit for review now or read more."
I have a contextMenu item which sends an Ajax request to a PHP script on my website.
The PHP script creates a .txt file and returns the download URL to the extension again.
On the next step a Desktop Notification is shown and there I want to place the download link, so the user can download the created file.
The problem is that I can't use HTML there. I don't want to use createHTMLNotification which is deprecated, so my code is:
var url = 'http://mydomain.com/somefile.txt';
var notification = window.webkitNotifications.createNotification(
'48.png', 'Click to download', 'Some description');
notification.addEventListener('click', function() { // can't create <a> tag, so I'm tring with a click event.
notification.cancel();
window.open(url);
});
notification.show();
This (window.open()) opens the file in a new tab. But I want only to download it, without opening in the browser.
Any ideas?
I found a solution and since there are not any answers I will write it.
For downloading a file from given URL you can use the downloads API's download method:
function forceDownload(url) {
var filename = url.replace(/^.*\/|\.[^.]*$/g, ''); // get basename
chrome.downloads.download(
{url: url, saveAs: true}, // options array
function(id) {
// callback function
}
);
};
In my situation forceDownload() method is called in the Ajax' done method:
function exportEntries(info, tab) {
var user = 'blah blah';
$.ajax({
url: 'http://domain.com/export.php',
method: 'POST',
data: { topic: tab.url, user: user }
}).done(function ( url ) {
forceDownload(url);
});
}