Lucas
06/28/2022, 4:39 AMModelsInit.context.setSessionObject('variableSet', true);
var session = ModelsInit.context.getSessionObject('variableSet');
Marvin
06/28/2022, 4:46 AMUncaught Error: Module "SC.Models.Init" on "<http://localhost:7777/SC.Models.Init.js>" not found
Can you not load it into a View?Lucas
06/28/2022, 4:47 AMLucas
06/28/2022, 4:48 AMMarvin
06/29/2022, 4:51 AMSC.Models.Init
only available for suitescript 1.0 backends? I seem to be very confused on where I can load it.Lucas
06/29/2022, 7:37 AMLucas
06/29/2022, 7:40 AMLucas
06/29/2022, 7:40 AMdefine('SessionExample', ['Models.Init'], function ( ModelsInit){
'use strict';
return SCModel.extend({
name: 'SessionExample',
get: function () {
ModelsInit.context.setSessionObject('SessionExample', true);
}
})
});
Lucas
06/29/2022, 7:41 AMUncaught Error: Module "SC.Models.Init" on "<http://localhost:7777/SC.Models.Init.js>" not found
Regarding above error, Have you deployed your code/extension?Lucas
06/29/2022, 7:44 AMLucas
06/29/2022, 7:44 AMLucas
06/29/2022, 7:44 AMMarvin
06/29/2022, 4:44 PMSC.Models.Init
to set a session which worked. But you pointing me to the fact that N/runtime
sets sessions. Can't believe I never saw that before since I use that module all the time when building suitescripts.
Can I ask how you determine request method from frontend requests?
The following does a GET request to the suitescript backend service controller.
const orderModel = new OrderModel();
orderModel.fetch({
data: {
order_id: uri_matches[2]
}
})
.done(result => {
});
How would I do a POST request to a Suitescript v2 backend?Lucas
07/01/2022, 8:24 AM////SS file
/**
* @NApiVersion 2.x
* @NModuleScope Public
* // Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* // Licensed under the Universal Permissive License v 1.0 as shown at <http://oss.oracle.com/licenses/upl>.
*/
define([
'./Demo.SS2Model.js',
'N/runtime'
], function (
DemoSS2Model,
runtime
) {
'use strict';
function isLoggedIn () {
var user = runtime.getCurrentUser();
return user.id > 0 && user.role !== 17
}
function service (context) {
var response = {};
if (isLoggedIn()) {
switch (context.request.method) {
case 'GET':
response = DemoSS2Model.get(context)
break;
case 'POST':
response = <http://DemoSS2Model.post|DemoSS2Model.post>(context)
break;
default:
response = {
type: 'error',
message: 'Method not supported: ' + context.request.method
};
}
}
else {
response = {
type: 'error',
message: 'You must be logged in to use this service'
}
}
context.response.write(JSON.stringify(response));
}
return {
service: service
}
})
Lucas
07/01/2022, 8:24 AM//Model file
/**
* @NApiVersion 2.x
* @NModuleScope Public
*/
define([
'N/record','N/search','N/runtime','N/log','N/url','N/https'
], function(
record,search,runtime,log,url,https
){
'use strict';
return {
get: function(context){
if(context){
try{
var user = runtime.getCurrentUser();
//------- Your Code
return {message: "your get result"};
}
catch(e){
return e;
}
}
},
post: function(context){
if(context){
try{
var user = runtime.getCurrentUser();
//------- Your Code
return {message: "your post result"};
}
catch(e){
return e;
}
}
}
}
});
Lucas
07/01/2022, 8:26 AM//your js view file
this.model = new DemoSS2Model();
this.model.fetch({
type: "post",
data:{
internalid:1234,
email:'email'
}
, killerId: AjaxRequestsKiller.getKillerId()
}).done(function(result) {
if (result) {
var message= result.message;
self.render();
self.showSuccess(type,message);
}
});
Lucas
07/01/2022, 8:27 AMLucas
07/01/2022, 8:27 AMLucas
07/01/2022, 8:28 AMMarvin
07/01/2022, 4:49 PM.fetch
. Appreciate the help.