Hi all, How to get Customer Fields in 20.2 Backend...
# suitecommerce
s
Hi all, How to get Customer Fields in 20.2 Backend Model Using 2.0 Script.
s
If you want data fields about the current user then you can use the N/runtime module. If you want to get fields from their record, you can use the internal ID of that user to load a customer record using N/record
s
Hi Steve, When i am trying to load the Customer Record in Backend Model. I am facing the permission related issue, is there any solution for that.
s
You will need to elevate the permissions on the service file so that it executes the file with sufficient additional permissions. For example, as the Advanced Customer Center.
Just be warned that this means you're granting your script privileges to view/edit customer records, so you will need to make sure that it's not possible for a user to use this to look up someone else's record data
s
Hi Steve, when I'm trying to get the ContextDate.item() in my custom function using SC View. I'm facing this issue.
message has been deleted
s
Can you share your code?
s
define('Netscore.LoyaltyPointsinPLPPDP.LoyaltyPointsinPLPPDP.View', [ 'SCView', 'netscore_loyaltypointsinplppdp_loyaltypointsinplppdp.tpl', "Netscore.LoyaltyPointsinPLPPDP.LoyaltyPointsinPLPPDP.Model" ], function ( SCViewModule, netscore_loyaltypointsinplppdp_loyaltypointsinplppdp_tpl, LoyaltyPointsinPLPPDPModel ) { 'use strict'; var Environment; var SCView = SCViewModule.SCView; function LoyaltyPointsinPLPPDPView (options) { SCView.call(this, options); this.template = netscore_loyaltypointsinplppdp_loyaltypointsinplppdp_tpl; this.contextDataRequest = ['item']; Environment=options.Environment; var slef=this; this.model=new LoyaltyPointsinPLPPDPModel(); this.model.fetch().done(function(){ slef.render(); }); } function getItemEligibility(){ var isEligible; var item=this.contextData.item(); console.log("item",item); isEligible=item.custitem_item_is_eligible; if((isEligible != 'undefined') ||(isEligible != '') || (isEligible != null)) { return isEligible; } return false; } LoyaltyPointsinPLPPDPView.prototype = Object.create(SCView.prototype); LoyaltyPointsinPLPPDPView.prototype.constructor = LoyaltyPointsinPLPPDPView; LoyaltyPointsinPLPPDPView.prototype.render = function () { SCView.prototype.render.call(this); } LoyaltyPointsinPLPPDPView.prototype.getContext = function () { console.log("thiss",this.model); //debugger; var isLoggedIn; var isLoyaltyEnabled=Environment.getConfig('loyaltyapp.enableloyaltyprogram'); console.log("isLoyaltyEnabled",isLoyaltyEnabled); var isEnableDisplayPointsPLP=Environment.getConfig('loyaltyapp.enablepointsdisplayplp'); console.log("isEnableDisplayPointsPLP",isEnableDisplayPointsPLP); var isCustomerELigibleforLoyalty='F',userid,isLoggedIn; isCustomerELigibleforLoyalty=this.model.get("iseligibleforloyalty"); userid=this.model &&this.model.get("cust_id"); if(userid!=0) isLoggedIn=true; else isLoggedIn=false; return { isProductEligible:getItemEligibility(), // points: this.getPointsforThisItem(), isCustomerELigibleforLoyalty: isCustomerELigibleforLoyalty, isLoggedIn: isLoggedIn, isLoyaltyEnabled: isLoyaltyEnabled, isEnableDisplayPointsPLP: isEnableDisplayPointsPLP }; } return LoyaltyPointsinPLPPDPView })
s
OK, there are quite a few mistakes and bad practices here
But I think the primary problem that you are experiencing is that your function
getItemEligibility
is probably in the wrong place. In your constructor function, you should define
getItemEligibility
as a property of
this
, rather than having it in the body of the module.
s
Is there any example for that.
s
You use
this.[property]
in your own code...
s
var item=this.contextData.item(); that line I wrote directly in initialize function only, but still I'm getting the same error.
s
SCView derived classes don't have an
initialize
function, their constructors act like
initilalize
. The point is that if you're going to have
getItemEligibility
function, then you should be putting this as a property in your constructor. Eg,
this.getItemEligibility = function () {...}
. In that function you should then be able to use
this.contextData
, or, at least, pass it in.
s
Hi Steve, I'm trying to display one value in PLP page for all items, that value came from backend model. The value will be displayed ,but it takes some time. So for that I'm using self.render(),but its not working, can you help me on that.
s
Generally speaking, sure. What exactly is the problem?
s
I,m trying to display some points based on item price in PLP. Here the issue is points will be displayed after some time when the page is loaded.
How to display those points after page rendered.
s
The fetch to get the points should return a promise. Using a done() or then() handler, you can tell the view to render when the fetch completes.
s
Hi Steve, I've wrote the code like this, but still i am facing the same issue.
this.model=new mymodel(); this.model.fetch().then(function(){ self.render(); });