- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 02:45 PM
Hello all,
This is more of a personal project... I'm playing with Google Gemini, it works well from a Q&A perspective e.g. "Describe an egg". However I wanted to give it something more challenging and cant get it to work
Below is a UI Action I've whipped together to look at the sys_update_xml table in order to summarise an update set. but whenever I run it the API is called and it just falls over, any ideas would be greatly appreciated.
(function executeAction() {
action.setRedirectURL(current);
var payloads = [];
var childsets = new GlideRecord("sys_update_xml");
childsets.addQuery("update_set", current.sys_id);
childsets.orderBy("sys_updated_on");
childsets.query();
while (childsets.next()) {
if (!childsets.payload.nil()) {
payloads.push(childsets.payload.toString());
}
}
if (payloads.length === 0) {
gs.addInfoMessage("No XML changes found to process.");
return;
}
try {
// Construct the API request body
var requestBody = JSON.stringify({
contents: [{
parts: [{
text: "Please summarize this XML Data" + payloads.join("\n\n") // Format payloads as a readable block
}]
}]
});
var request = new sn_ws.RESTMessageV2('GoogleGemini', 'POST'); // Use the existing API definition
request.setRequestBody(requestBody);
var response = request.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("GoogleGemini API Response: " + responseBody);
if (httpStatus == 200) {
var responseJson = JSON.parse(responseBody);
if (responseJson && responseJson.responseBody) {
current.description = responseJson.responseBody;
current.update();
gs.addInfoMessage("Technical description generated successfully.");
} else {
gs.addErrorMessage("GoogleGemini API did not return a valid description.");
}
} else {
gs.addErrorMessage("GoogleGemini API failed with HTTP status: " + httpStatus);
}
} catch (ex) {
gs.error("Error calling GoogleGemini API: " + ex.message);
gs.addErrorMessage("An error occurred while calling GoogleGemini API.");
}
})();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 05:31 AM
@Ankur Bawiskar I managed to fix it. Here's the script I used.
action.setRedirectURL(current);
var ask = "summarise";
var payloads = [];
var xmlgr = new GlideRecord("sys_update_xml");
xmlgr.addQuery("update_set", current.sys_id);
xmlgr.query();
while (xmlgr.next()) {
if (!xmlgr.payload.nil()) {
payloads.push(xmlgr.payload.toString());
}
}
// Combine all payloads into a single string
var payloadText = payloads.join("\n\n"); // Separate payloads for readability
try {
var body = JSON.stringify({
"contents": [{
"parts": [{
"text": ask + " " + payloadText + " " + current.description.toString()
}]
}]
});
var r = new sn_ws.RESTMessageV2('GoogleGemini', 'POST');
r.setRequestBody(body);
var response = r.execute();
var responseBody = response.getBody();
var res = JSON.parse(responseBody);
current.description = res.candidates[0].content.parts[0].text;
current.update();
} catch (ex) {
gs.error("AI Summary Error: " + ex.message);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 12:46 AM
Hi, this looks like the response back from your rest message. When you do a business rule or UI Action for example you need to include a command in the question.
In my script I added the variable of
var ask = "summarise";
Then used this in my call…
try {
var body = JSON.stringify({
"contents": [{
"parts": [{
"text": ask + " " + payloadText + " " + current.description.toString()
}]
}]
});
So what I’m doing is asking Gemini to Summarise the Payload text.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 01:47 AM
Hi @Community Alums ,
Thanks for the reply, Correct i am calling rest message form Ui action and setting response in the knowledge article body based on the article short description, i think in my case
PayloadText is not required, but it is still same behaviour even if i use
var ask = "summarise";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 12:31 PM
Hi @Dhanunjay2 yeah exactly, you’re asking Gemini to “Summarise” followed by the current.short_description. Ignore payload because in mine I’m getting it to summarise a bunch of update set XML data.