transform script status_message not updating in SOAP response body in servicenow - servicenow

I am created a onBefore transform script.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if(source.u_incident.nil()){
status_message="The Record is not inerted";
error_message="ERR001 Cell number can't be empty!";
ignore = true;
}
})(source, map, log, target);
I am sending the request from SOAP UI, if the u_incident value is empty it is not creating the new one as we mentioned ignore=true, but in the SOAP response body I am not getting status_message and error_message as expected the default messages are coming.

try
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if(source.u_incident.nil()){
response.status_message="The Record is not inerted";
response.error_message="ERR001 Cell number can't be empty!";
ignore = true;
}
})(source, map, log, target);

Related

getAttachmentContentAsync does not return anything

I've read the documentation over on: https://learn.microsoft.com/en-us/javascript/api/outlook/office.messagecompose?view=outlook-js-preview&preserve-view=true#getComposeTypeAsync_options__callback_ , but nothing has been returned. Not even error messages. It doesn't return anything at all. The code i've used is below:
var item = Office.context.mailbox.item;
var options = {asyncContext: {currentItem: item}};
item.getAttachmentsAsync(options, callback);
function callback(result) {
if (result.value.length > 0) {
for (i = 0 ; i < result.value.length ; i++) {
result.asyncContext.currentItem.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
}
}
}
function handleAttachmentsCallback(result) {
// Parse string to be a url, an .eml file, a base64-encoded string, or an .icalendar file.
switch (result.value.format) {
case Office.MailboxEnums.AttachmentContentFormat.Base64:
// Handle file attachment.
console.log(result.value.content);
break;
case Office.MailboxEnums.AttachmentContentFormat.Eml:
// Handle email item attachment.
console.log("Attachment is a message.");
break;
case Office.MailboxEnums.AttachmentContentFormat.ICalendar:
// Handle .icalender attachment.
console.log("Attachment is a calendar item.");
break;
case Office.MailboxEnums.AttachmentContentFormat.Url:
// Handle cloud attachment.
console.log("Attachment is a cloud attachment.");
break;
default:
// Handle attachment formats that are not supported.
}
}
I have inserted the code for the MessageCompose form and I know that it requires the v1.8 API. I have tested other methods such as getAttachmentsAsync(options, callback) and they work as expected.
As a test, I have been using console logs at specific points where the code works up to. The console outputs the result of callback(result) as OSF.DDA.AsyncResult where status=succeeded. However, it displays "This value was evaluated upon first expanding. It may have changed since then." and it won't allow me to inspect the Object when you click expand.
Additionally logging result.value[i] in callback works as well, with the same issue where I cant expand the object for more details.
Why won't getAttachmentContentAsync return anything?

Jenkins Groovy Active choice parameter how to pass first dropdown values to second dropdown boy

How do I pass the selected value from the first dropdown to the second drop down ?
this is the link I am following [link][1]
// Import the JsonSlurper class to parse Dockerhub API response
import groovy.json.JsonSlurper
// Set the URL we want to read from, it is MySQL from official Library for this example, limited to 20 results only.
docker_image_tags_url = "https://hub.docker.com/v2/repositories/library/mysql/tags/?page_size=20"
try {
// Set requirements for the HTTP GET request, you can add Content-Type headers and so on...
def http_client = new URL(docker_image_tags_url).openConnection() as HttpURLConnection
http_client.setRequestMethod('GET')
// Run the HTTP request
http_client.connect()
// Prepare a variable where we save parsed JSON as a HashMap, it's good for our use case, as we just need the 'name' of each tag.
def dockerhub_response = [:]
// Check if we got HTTP 200, otherwise exit
if (http_client.responseCode == 200) {
dockerhub_response = new JsonSlurper().parseText(http_client.inputStream.getText('UTF-8'))
} else {
println("HTTP response error")
System.exit(0)
}
// Prepare a List to collect the tag names into
def image_tag_list = []
// Iterate the HashMap of all Tags and grab only their "names" into our List
dockerhub_response.results.each { tag_metadata ->
image_tag_list.add(tag_metadata.name)
}
// The returned value MUST be a Groovy type of List or a related type (inherited from List)
// It is necessary for the Active Choice plugin to display results in a combo-box
return image_tag_list.sort()
} catch (Exception e) {
// handle exceptions like timeout, connection errors, etc.
println(e)
}
I have another active choice box groovy script,expecting a value from the above dropdown
box. I have tried
env = params.mysql_image_version
// def env="dev" // this works but I am hard coding the value ,instead of getting it dynamically from the above dropdown box
env_list.each { env ->
stack_list.add(github_response.get("dev"))
}
print stack_list

C++ builder indy intercept IdHTTPProxyServer to insert header

I want to insert header of external script over https inside browser. For those purpose i use C++ builder with IdHTTPProxyServer component. I read Document from Response event but dont know how to just insert one simple .js. -> cause Document property is read only, on the other side BeforeCommandHandler want append with script (in code under i use just text to insert for simplicity)
How to insert .js external script in C++ builder?
Here is what i done so far.
void __fastcall TForm5::IdHTTPProxyServer1HTTPResponse
(TIdHTTPProxyServerContext *AContext)
{
Memo1->Lines->Append("\nOn Response!!!\n" + AContext->Document);
}
void __fastcall TForm5::IdHTTPProxyServer1BeforeCommandHandler
(TIdCmdTCPServer *ASender, UnicodeString &AData, TIdContext *AContext) {
try {
Memo1->Lines->Add(AData);
UnicodeString sa = AData;
AData = L"<html>Something</html>" + sa;
}
catch (int e) {
MessageBeep(100);
}
}
The TIdHTTPProxyServer::OnBeforeCommandHandler event is triggered before a client's request is processed. The AData parameter is the original request. This event is meant for logging/altering commands before they are parsed.
The TIdHTTPProxyServer::OnHTTPBeforeCommand event is triggered after a client's request headers have been received but before a connection is established to the target server and the client's request body is read and sent to the server.
The TIdHTTPProxyServer::OnHTTPResponse event is triggered after a server's response headers have been received but before the response body is read and sent to the client.
So none of those events will help you.
Neither will the TIdHTTPProxyServerContext::Document property, for that matter. That property does not contain the document data, as you are assuming. It contains the server-relative URL of the document being requested instead.
To do what you are asking for, set the TIdHTTPProxyServer::DefaultTransferMode property to tmFullDocument and use the OnHTTPDocument event. The TIdHTTPProxyServerContext::TransferSource property will tell you if the data is coming from the client or the server.
You will have full access to the headers and body data and you can modify them as needed. Just make sure you update the TIdHTTPProxyServerContext.Headers, in particular the Content-Length header, if you modify the body data. The body data is provided as a TStream object (specifically, a TMemoryStream). So you can either modify the stream's content directly, or you can create a new TStream object with your desired content (the VStream parameter of the event is passed by reference so you can re-assign it).
For example:
void __fastcall TForm5::IdHTTPProxyServer1HTTPDocument(TIdHTTPProxyServerContext* AContext, TStream* &VStream)
{
if (AContext->TransferSource == tsServer)
{
String s = ReadStringAsContentType(VStream, AContext->Headers->Values[L"Content-Type"], QuoteHTTP);
// this is NOT thread-safe! TIdHTTPProxyServer is multi-threaded,
// you must synchronize with the main thread in order to safely
// update UI controls...
//
// Memo1->Text = s;
s = L"<html>Something</html>" + s;
delete VStream;
VStream = new TStringStream(s, Sysutils::TEncoding::UTF8);
AContext->Headers->Values[L"Content-Length"] = VStream->Size;
AContext->Headers->Params[L"Content-Type"][L"charset"] = L"utf-8";
}
}

Service Bus - Retrieve message from session by sequence number

I am currently trying to retrieve a specific message from a session.
To do so I use want to use the .Receive(Int64) on the MessageSession where I pass in the sequence number of the message.
Here is my code -
long msgSequenceNr = 1337;
QueueClient queueClient = QueueClient.CreateFromConnectionString(Constants.ServiceBusConnectionString, Constants.TestQueueEntityName, ReceiveMode.PeekLock);
MessageSession msgSession = queueClient.AcceptMessageSession(Constants.TestSessionId);
var peekedMsg = msgSession.Peek(msgSequenceNr); // <-- Works fine!
var receivedMsg = msgSession.Receive(msgSequenceNr); // <-- MessageNotFoundException
Unfortunately the Receive will result in a MessageNotFoundException while the Peek works fine.
Is this a limitation that I missed or is there another way to achieve this.
Note that it is possible that there are multiple messages in the session
Receive with the SequenceNumber can only be used in combination with the Defer method. This is how you would implement it:
Message received, but it can't be processed right now (maybe it's waiting for a different process to complete).
Persist the SequenceNumber in some persistent storage (Table Storage, SQL Database, ...)
When you know that processing can continue (eg: the dependent process is complete), load all SequenceNumbers from your persistent storage.
Use Receive(int sequenceNumber) or ReceiveBatch(int[] sequenceNumbers) to received and process your deferred messages.
Sample application: https://code.msdn.microsoft.com/windowsazure/Brokered-Messaging-ccc4f879#content
Update:
Form your comment I noticed that "undeferring" a deferred message could be a solution. Here's some sample code to undefer the message which copies the deferred message to a new message, Completes the deferred message and sends the new message back in the queue. This uses a TransactionScope to transactionally Complete and Resend the message to avoid the risk of losing the message:
var messageId = "12434539828282";
// Send.
var msg = new BrokeredMessage {SessionId = "user1", MessageId = messageId };
msg.Properties.Add("Language", "Dutch");
queue.Send(msg);
// Receive.
var session = queue.AcceptMessageSession();
msg = session.Receive();
// Store the sequence number.
var sequenceNumber = msg.SequenceNumber;
// Defer.
msg.Defer();
// Change to true to test if the transaction worked.
var shouldThrow = false;
// Later processing of deferred message.
msg = session.Receive(sequenceNumber);
try
{
using (var ts = new TransactionScope())
{
// Create a new message.
var undeferredMessage = new BrokeredMessage {SessionId = msg.SessionId, MessageId = msg.MessageId};
foreach (var prop in msg.Properties)
undeferredMessage.Properties.Add(prop);
// Complete and send within the same transaction.
msg.Complete();
if (shouldThrow)
throw new InvalidOperationException("Some error");
queue.Send(undeferredMessage);
// Complete the transaction.
ts.Complete();
}
}
catch (Exception ex)
{
msg.Abandon();
}
if (shouldThrow)
{
msg = session.Receive(sequenceNumber);
Console.WriteLine(msg.MessageId + " should match: " + messageId);
}
else
{
try
{
msg = session.Receive(sequenceNumber);
}
catch (Exception ex)
{
Console.WriteLine("Message not found, transaction worked OK.");
}
}
Note: here I'm simply taking a copy of the Properties. Keep into account that you might want to copy the Body and any other additional information.

Kendo UI - how to implement Error Handling on WEB API, non MVC using Kendo Grid

My Scenario is I created a Web API that returns an Active Directory Object.
I have this WEB API function create Active Directory User and creates a user that returns Active Directory Object that contains First Name , Last Name, Email, UserName, Etc... What If it got an error how would I handle this?
I'm using Kendo Grid InLine Edit http://demos.kendoui.com/web/grid/editing-inline.html
I want to show the error message as a pop up window
How would I do that???
Options
try catch the error and put in the Active Directory Object as
Exception???
How can I capture this is Kendo UI?
Throw the response and get the error message and show it in the Kendo Grid
//HttpResponseMessage msg = new HttpResponseMessage(HttpStatusCode.OK)
//{
// Content = new StringContent(string.Format("No User with ID = {0}.{1}", businessObject.UserName, ex.InnerException.ToString() )),
// ReasonPhrase = "CustomerID Not Found in Database!"
//};
//throw new HttpResponseException(msg);
OR
//var message = string.Format("Error Message: {0}", taskCreateADUser.ADExceptionDescription);
//throw new HttpResponseException(
// Request.CreateErrorResponse(HttpStatusCode.OK, message));
Thanks,
MarcLevin
Whenever KendoUI binds via Ajax it relies on serialized version of ModelState sent in json response. Essentially if ModelState is not valid, the json response returned to the widget (grid in this case) will contain something like this:
{
"Errors":{
"PropA":{
"errors":[
"Error1",
"Error2"
]
},
"PropB":{
"errors":[
"FUBAR"
]
}
}
}
Essentially your WebAPI will need to return similar data structure if you want the grid to respond to it.
This is regarding your Option 2. You would need to apply the following correctly to your specific scenario. This is just a sample of a really simple parse of the response and displaying an alert if an error is detected. This sample expects a JSON object containing an array of Items. You could definitely apply more advanced handling once you have the basic idea down.
$("#grid").kendoGrid({
dataSource: {
schema: {
data: function(data) {
if (data.Items[0].substring(0,37) == "allmyerrormessagesstartwiththisphrase"){
alert(data.Items[0];
} else {
return data.Items;
}
}
},
transport: {
read: "http://myurl.com/something/"
}
}
}
);

Resources