How to Get Cart Data in NetSuite SiteBuilder Application - netsuite

I am new in NetSuite Development.
I want to fetch list of product which are added in the cart to show Short Summary in Header Section. Like Item thumbnail, qty, and price.
Can anyone help me how to do this, or what I need to read to accomplish this task.
Any Help will be appreciated.
Thanks.

Probably the easiest thing to do is create an SSP application and pull the cart as a JSON object from a cart.ss url.
I know the old reference checkout had a /services/cart.ss file that could be used for this (free bundle from Netsuite)
You may be able to get away with a really simple script for that:
/ssp root url/services/cart.ss
service(request, response){
var session = nlapiGetWebContainer().getShoppingSession();
var orderObj = session.getOrder();
response.setContentType('JSON');
response.writeLine(JSON.stringify({order: orderObj.getFieldValues()}));
}
Then when you've published the SSP application you'd access this as an root relative url from the site.

Related

What is the Sharepoint Document Location endpoint really returning?

I'm trying to get the OneNote notebook information that is linked to my organization's CRM accounts. Each account has a OneNote book created for it that can be accessed inside of CRM.
From what I understand, I can use the SharePointDocumentLocation endpoint (found here: https://learn.microsoft.com/en-us/dynamics365/customer-engagement/web-api/sharepointdocumentlocation?view=dynamics-ce-odata-9) to get the location of the specific file if I ask for location type to be 1.
However, SharePointDocumentLocationId and SiteCollectionId don't seem to be pointing to anything on my company's sites. Should I be getting my data somewhere else?
I started searching through my company's SharePoint structure to see if I can get any hints as to where these documents may be located. My initial Postman request (getting the sites off of the root site) don't show the site that hosts our CRM documents (sites/crmdocs). I was able to find where this was stored eventually, but trying to get the OneNote notebooks stored there returns an error since we have more than 20,000 notebooks there, so I can't fetch them all. As far as I know, I'm able to get notebooks if I have the specific ID I want.
Once I fetch the CRM information, I try to send a request like this:
https://graph.microsoft.com/v1.0/sites/{myCompanyUrl},{siteCollectionId},{sharepointDocumentLocationId}/onenote/notebooks/
SiteCollectionId and SharePointDocumentLocationId are from my CRM SharePointDocumentLocation request
The error I receive is:
The requested site was not found. Please check that the site is still accessible.
Assuming your environment is using the out of the box sharepoint site and sharepoint document location hierarchy, you can access One Note files using the following link structure:
[SharePointAbsoluteUrl]/[EntityLogicalName]/[RelativeUrl]_[RegardingObjectId]/[RelativeUrl]
How to get [SharePointAbsoluteUrl] :
Querying for sharepointdocumentlocations is actually not enough because Dynamics 365 stores this information in another entity called sharepointsite. This is how you can obtain it:
var query = new QueryExpression("sharepointsite")
{
ColumnSet = new ColumnSet("absoluteurl")
};
query.Criteria.AddCondition("IsDefault", ConditionOperator.Equal, true);
var entityCollection = _service.RetrieveMultiple(query);
var absoluteUrl = entityCollection[0].Attributes["absoluteurl"];
In Web API it is equivalent to:
GET https://[Your Org]/api/data/v9.0/sharepointsites?$select=absoluteurl&$filter=isdefault%20eq%20true
There can only be a default sharepoint site so this query will return a single record.
How to get the remaining parts:
Fetch for sharepointdocumentlocations that have Location Type dedicated to One Note Integration:
var query = new QueryExpression("sharepointdocumentlocation")
{
ColumnSet = new ColumnSet("regardingobjectid", "relativeurl")
};
query.Criteria.AddCondition("locationtype", ConditionOperator.Equal, 1);
var entityCollection = _service.RetrieveMultiple(query);
In Web API it is equivalent to the following get request, don't forget to add add Prefer: odata.include-annotations="*" to your HTTP Request Headers so that it gets the lookup lookuplogicalname field:
GET https://[Your Org]/api/data/v9.0/sharepointdocumentlocations?$select=relativeurl,_regardingobjectid_value&$filter=locationtype%20eq%201
This query can return many records, I've only used the first one in the examples below for explanation purposes.
[EntityLogicalName] will be your ((EntityReference)entityCollection[0].Attributes["regardingobjectid"]).LogicalName;
In Web Api will be your value._regardingobjectid_value#Microsoft.Dynamics.CRM.lookuplogicalname value.
[RelativeUrl] will be your entityCollection[0].Attributes["relativeurl"];
In Web Api will be your value.relativeurl value.
[RegardingObjectId] can be obtained with this expression ((EntityReference)entityCollection[0].Attributes["regardingobjectid"]).Id.ToString().Replace("-", "").ToUpper();
In Web Api id will be your _regardingobjectid_value value and you have to remove dashes and convert it to upper case in whatever language you are doing the request.
You should end up with an URL like this https://mycompany.sharepoint.com/account/A Datum Fabrication_A56B3F4B1BE7E6118101E0071B6AF231/A Datum Fabrication

Get all items of a Sharepoint document library using Graph API

I'm trying to retrieve a document library by path using the Graph API and I'm not sure how to proceed.
The url to the library is for example the following:
https://hostname/sites/sitename/subsite/nameofdocumentlibrary/
I would like to have all the children through the Graph API. The issue: I know the document of the library but I don't know the ID of the library. It seems that it's possible to access it through the relative path but I'm not succeeding to it.
How do I do this?
My get url was the following:
/v1.0/sites/hostname:/sites/sitename/subsite/nameofdoccumentlibary/items
I'm always getting:
The provided path does not exist, or does not represent a site or UnknownError.
Any ideas ?
Try to use this:
GET https://graph.microsoft.com/v1.0/sites/{hostname},{spsite-id},{spweb-id}/lists/{list-id}
I don't check this in real life because I don't have SP Online. But it must working.
Use this link with SharePoint Graph API.
To get site id (site collection) you can go to your site collection and browse this endpoint:
https://hostname/sites/sitename/_api/site?$select=Id
To get web id (subsite) you can go to your subsite and browse this endpoint:
https://hostname/sites/sitename/subsite/_api/web?$select=Id
To get library Id you can just open Document Library Settings page. URL have library ID. You can transform it to real guid. Like this:
/_layouts/15/listedit.aspx?List=%7B603D7FA3-C801-46EB-A044-421234452901%7D
Must transformed to:
603D7FA3-C801-46EB-A044-421234452901
Following your feedback, I could now retrieve the document library using the display name (not the path in the url).
This is my request:
https://graph.microsoft.com/v1.0/sites/fullsubsiteid/lists/69369/items
69369 is my display Name here.
I can also use:
https://graph.microsoft.com/v1.0/sites/fullsubsiteid/lists/69369/drive
Now the first request, is returning an empty value array, while there is a "Documents" folder in the document library. How could I retrieve all folders/files etc in this document library? How can I use relative path?
Tx!

Netsuite, how to show popup after login into netsuite account?

I am new to Netsuite and I have a requirement to show one alert message displaying "welcomeuser" after the user loggedin into Netsuite account.
I have tried this client script but its not showing any message.
function employee_PageInit(type){
debugger;
alert('Dear UserName, The data in NetSuite is confidential and the property of the company.');
nlapiLogExecution('DEBUG', 'user role', nlapiGetContext().getName());
alert('ok'+ nlapiGetContext().getName());
}
I have logged in with the role ADMINISTRATOR,
any help is appreciated thank you.
Here is a sample with 2.0. It's not pretty and would need some work. But this is one way to inject javascript logic onto the homepage with a portlet.
/**
*#NApiVersion 2.x
*#NScriptType Portlet
*/
define(['N/runtime'],
function(runtime) {
function render(params) {
var user = runtime.getCurrentUser();
params.portlet.title = 'Welcome Message';
var content = '<script>alert(\'Hello ' + user.name + '\');</script>';
params.portlet.html = content;
}
return {
render: render
};
});
U can try using custom portlet it stands out in the dashboard for showing the content.Then also alert is not possible.
I've struggled with this idea in the past and what you want is not technically possible, since there are no scripts that run when you are viewing the homepage. Here are some weird workarounds:
Schedule a calendar reminder, which can trigger a pop-up with your message.
Before assigning their full NetSuite rights, tell users to go to a specific page or form: Maybe a custom record... (the record could serve as a log of who consented to and read your policy) On this form you could have your message. Then when the user fills it out, have a back-end script enable their permissions.
Make your text into a tiny image, and make it your company logo for all of NetSuite. ;)
You can add the custom Javasript to display the alert on a Suitelet which would be set as the Landing Page under General Preferences, then once the user accepts redirect to their home page, and if they don't accept send an alert to the admin...
E.g.
<script>
var accepted = confirm('Dear UserName, The data in NetSuite is confidential and the property of the company.');
if (accepted)
window.open('https://99999.app.netsuite.com/app/center/card.nl?sc=-29&whence=');
else
//Send email to admin
</script>
Hi please follow the following steps :
Create a suitelet script - Login Script with pageInit() in clientscript action to alert your welcome message.
Goto Setup > Company > General Preference and under Centers tab add appropriate URL of the Login Script Suitelet's deployment and save the preferences.
Note : You can add different messages to different center's based on the roles in your account.
General Preference > Centers Tab
Hope this solves your issue please revert back if anything is missed.
Basically, the homepage of NetSuite is not scriptable.
There are some ways to check if the record/page is scriptable:
Look up the specific record type in the NetSuite Help Center; specifically on the Records Browser
On the Browser's developer console, you may run nlapiGetRecordType() and if it returns the record name, it should be scriptable -- please note that the record should be on edit mode for the console tool to run correctly with NetSuite pages
Hope this helps with your development!
you can write a function
function pageInit(type){
var context= nlapiGetContext();
var username = context.getName();
alert(hello+username);
}

Log out NetSuite

I'm trying to create a Log out link in NetSuite I know that the code below works but when i place it in netsuite it just gets outputted as text. I'm just having trouble understanding where in NetSuite it actually goes. It does not work when I place it in a template.
<# var isLoggedIn = "<%=getCurrentAttribute('customer','email')%>" != ""; if(isLoggedIn) { <li class="dropdown-menu1"> Log out </li> } #>
isLoggedIn has been replaced with isLoggedIn2 FYI, or at least for the company that I work for this was the case and recommendation
You might:
A) Replicate the scripts called when you log out
B) Clear cookies and redirect to X page.
'isLoggedIn' method is no longer supported or recommended. This method works correctly in the Checkout domain but may return false when used in the Shopping domain even when the user is logged in. The method is currently being use in pre_Denali versions of SuiteCommerce Advanced. If you encounter session issues in those bundles, contact support to migrate to using the isLoggedIn2() method.
-- posted today on NetSuite's forum by an employee

web site scraping through Jsoup

I have spent few hours on signing in to web site by using jsoup. But it always gives same login page. To clarify the issue I tried with facebook site. It also gives same result.
Below I mentioned my code
String url ="http://www.facebook.com/";
Document doc;
doc = Jsoup.connect(url)
.data("email","abc#gmail.com","pass","xyz")
.userAgent("Mozilla").post();
System.out.println(doc);
can anybody point me where I made a mistake and how can i fix this issue?
In data portion "email" and "pass" are input field id of facebook login page.
Thank you.
Try this:
String url ="http://www.facebook.com/";
Document doc;
doc = Jsoup.connect(url)
.data("email","abc#gmail.com")
.data("pass","xyz")
.userAgent("Mozilla")
.post();
Anyway, Jsoup is not bad at all, you only need how to use it properly, but also you need to keep in mind that Facebook is expecting a lot more parameters to make a successfull login via POST emulating a web page navigation.
By example:
charset_test
default_persistent
lgnjs
lgnrnd
locale
lsd
pass
persistent
timezone
If you need to authenticate and get proper data I suggest that you must give a try to a Facebook SDK for Android:
https://github.com/facebook/facebook-android-sdk/

Resources