- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 01:56 PM
I have done something similar to this before for use in our Customer Portal and it all worked fine. I created the AWS SDK as a UI Script and created a dependency on a widget and was able to leverage all SDK functions easily. I am attempting to build a similar solution in the fulfiller interface using an UI Page.
I have tried numerous solutions from various different community posts. I will attempt to summarize a list of what I have tried already below but I do not expect it to be comprehensive.
The first list is the variety of ways I have tried to create the AWS SDK in a UI Script. The second list is how I attempted to initialize the UI Script inside my Client Script in my UI Page. For each example in the first list, I always attempted all initializations in the second list.
1. Use the existing AWS SDK UI Script that is currently working in the service portal. This exists inside my custom scoped application in which I am building this solution and has UI Type value of 'All'.
2. Create a globally scoped UI Script with UI Type set to Desktop.
2a. I also attempted to recreate the UI Page inside global scope and call this globally scoped UI Script.
3. Create another UI Script inside my scoped application set to UI Type Desktop.
4. Create another UI Script in global set to UI Type desktop but formatted in the default manner. I never got this to work because it is impossible to resolve all of the errors in the 15,000 line AWS SDK when inserted inside a function.
A. Error is always that globalAws is not defined. Got this one from like 3 different community posts. Just calling it like a script include did not seem like it would work but I tried anyway.
var AWS = new globalAws();
B. This one throws an error in console that says "Uncaught ReferenceError: g_ui_scripts is not defined". Go figure: GlideUIScripts - Client (servicenow.com)
g_ui_scripts.getUIScript('globalAws').then(function(AWS) {
AWS.config.update({
region: "us-east-2", // Is region of the Cognito user pool
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: "<idenity ID>",
Logins: {
"<cognitoidentiy>": loginToken // loginToken comes from a server side function
}
})
});
var s3 = new AWS.S3({
apiVersion: '2006-03-01',
region: selectedRegion});
var singleParams = {
Key: "test/" + filename,
Body: file,
Bucket: "<bucketName>"
};
s3.upload(singleParams,
function(err, data){
if (err){
console.log('error: ' + JSON.stringify(err) + " data: " + data);
}
else {
console.log('Successfully uploaded: ', singleParams);
}
})
}, function() {
console.log("the script did not load");
});
C. Nested callback function as found in this post: Solved: UI Script - Global checkbox = false - Application ... - ServiceNow Community
function clientCallbackFunc() {
console.log("inside callback"); // this always logs but it fails right after
awsSdk2.config.update({
region: "us-east-2", // Is region of the Cognito user pool
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: "<idp id>",
Logins: {
"<cognito id>": loginToken // loginToken comes from a server side function
}
})
});
console.log("below config update");
var s3 = new awsSdk2.S3({
apiVersion: '2006-03-01',
region: selectedRegion});
var singleParams = {
Key: "test/" + filename,
Body: file,
Bucket: "<bucketName>"
};
s3.upload(singleParams,
function(err, data){
if (err){
console.log('error: ' + JSON.stringify(err) + " data: " + data);
}
else {
console.log('Successfully uploaded: ', singleParams);
}
})
}
ScriptLoader.getScripts("x_borpp_ext_file.awsSdk2.jsdbx", clientCallbackFunc);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2023 02:08 PM
I got this to work by using the callback function method described in this post: Solved: UI Script - Global checkbox = false - Application ... - ServiceNow Community
I called the AWS SDK directly from the publicly available js file.
ScriptLoader.getScripts(['https://sdk.amazonaws.com/js/aws-sdk-2.1.24.min.js'], clientCallbackFunc); // AWS SDK loaded from public URL source
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2023 02:08 PM
I got this to work by using the callback function method described in this post: Solved: UI Script - Global checkbox = false - Application ... - ServiceNow Community
I called the AWS SDK directly from the publicly available js file.
ScriptLoader.getScripts(['https://sdk.amazonaws.com/js/aws-sdk-2.1.24.min.js'], clientCallbackFunc); // AWS SDK loaded from public URL source