You need to install the typings for Microsoft AJAX and JSOM. To do that run the below commands:
tsd install microsoft.ajax
tsd install sharepoint
After that, you need to add the config.json
you need to add below entries:
{
"sp-init": {
"path": "https://tenantname.sharepoint.com/_layouts/15/init.js",
"globalName": "$_global_init"
},
"microsoft-ajax": {
"path": "https://tenantname.sharepoint.com/_layouts/15/MicrosoftAjax.js",
"globalName": "Sys",
"globalDependencies": [ "sp-init" ]
},
"sp-runtime": {
"path": "https://tenantname.sharepoint.com/_layouts/15/SP.Runtime.js",
"globalName": "SP",
"globalDependencies": [ "microsoft-ajax" ]
},
"sharepoint": {
"path": "https://tenantname.sharepoint.com/_layouts/15/SP.js",
"globalName": "SP",
"globalDependencies": [ "sp-runtime" ]
}
}
Once you have added the entries, you need to add require
statements for them in your webpart as below:
require('sp-init');
require('microsoft-ajax');
require('sp-runtime');
require('sharepoint');
After that, inside your render method , you can use that JSOM code that you posted above.