How to query from URL "Line" Format to VBA variable - visual-studio-2010

I'm trying to make an application that will display user data through api on command... I have assembled the URL generator and everything. it's just beyond me to find a simple way to assign THIS: "http://api.bf4stats.com/api/playerInfo?plat=xbox&name=charlie%20is%20tftc&output=lines" data to specific variables with my parameters. (Lines / Text format)
This is my code so far, I just want to be able to assign data like 'player.id' to playerid and display it. (Player.id is the first value in the data linked above)
//the code below will be changed to user input, I don't need help with that this was just for theory
Public Class Form1
Public Sub URL_Player_Info(ByVal Address As String)
'Assign all data figures for constructing the "URL"...
Dim url, plat, player, webprefix, domain, paramsym, ext, preplat, preplayer, andsym, lineparam, format As String
'Variables for "Plat"
plat = "xbox"
'Input for "Player"
player = "Charlie Is TFTC"
'Structure for "URL"
webprefix = "http://"
domain = "api.bf4stats"
ext = ".com/api/playerInfo"
paramsym = "?"
preplat = "plat="
andsym = "&"
preplayer = "name="
format = "output="
lineparam = "lines"
'Generate Final "URL"
url = webprefix + domain + ext + paramsym + preplat + plat + andsym + preplayer + player + andsym + format + lineparam
'Getting Data / Assigning Data for "Plat. Player: Params"
End Sub
Thanks in advanced!

Related

Using Find to find a user property in Outlook/Redemption

I'm trying to return a single calendaritem from Outlook from our C# windows desktop application. It keeps returning this error:
Redemption.RDOItems
Assertion failed: Number of fields == 1.
I use similar code in an Outlook addin I created and it works fine. The main difference is the filterprefix.
In the AddIn I use:
string filterprefix = "[" + OurCustomProperty.OurItemId + "] = '";
var filter1 = filterprefix + parentItem.NeedlesId + "'";
var findItem = folder.Items.Find(filter1);
but this code does not work from our desktop app.
Here is the code from the desktop App which is returning the error:
The appointment.Id contains a valid value which we set when we create the item.
string Filterprefix = "#SQL="+"http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/OurCustomProperty.OurItemId/0x0000001f = '";
RDOSession rdoSession = new RDOSession();
rdoSession.Logon("", "", false, false, null, false);
RDOFolder folderRDO = rdoSession.GetDefaultFolder(rdoDefaultFolders.olFolderCalendar);
var filter1 = filterprefix + appointment.Id + "'";
string ls_find = Filterprefix + appointment.Id + "'" ;
var findItem = folderRDO.Items.Find(ls_find);
I've tried several variations of the syntax but can't seem to get it right.
I also tried using Sort then Restrict but no luck with that either.
Thanks, Rick
RDOItems.Find takes a SQL statement, please do not use the #SQL= prefix - it is OOM specific. Also do not forget to doublequote the DASL property name:
"http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/OurCustomProperty.OurItemId/0x0000001f" = '<some value>'

Servicenow script infinite recursion

I have the following ServiceNow script which inserts the record into live_message table.
(function executeRule(current, previous/*null when async*/) {
var requestBody;
var responseBody;
var status;
var request;
var response;
try {
request = new sn_ws.RESTMessageV2("LiveMessageWebhook", "post");
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var parameters = "&chat_message=" + current.chat_message.toString();
parameters = parameters + "&context=" + current.context.toString();
parameters = parameters + "&formatted_message=" + current.formatted_message.toString();
parameters = parameters + "&has_attachments=" + current.has_attachments.toString();
parameters = parameters + "&has_links=" + current.has_links.toString();
parameters = parameters + "&has_tags=" + current.has_tags.toString();
parameters = parameters + "&ID=" + current.id.toString();
parameters = parameters + "&in_reply_to=" + current.in_reply_to.toString();
parameters = parameters + "&isLiked=" + current.is_liked.toString();
parameters = parameters + "&lastActivity=" + current.last_activity.toString();
parameters = parameters + "&lastMessage=" + current.last_message.toString();
parameters = parameters + "&likeCount=" + current.like_count.toString();
parameters = parameters + "&message=" + current.message.toString();
parameters = parameters + "&next_reply_order_chunk=" + current.next_reply_order_chunk.toString();
parameters = parameters + "&order=" + current.order.toString();
parameters = parameters + "&poll=" + current.poll.toString();
parameters = parameters + "&private=" + current.private_message.toString();
parameters = parameters + "&profile=" + current.profile.toString();
parameters = parameters + "&reflected_field=" + current.reflected_field.toString();
parameters = parameters + "&reply_to=" + current.reply_to.toString();
parameters = parameters + "&state=" + current.state.toString();
parameters = parameters + "&group_type=" + current.sys_class_name.toString();
parameters = parameters + "&created_by=" + current.sys_created_by.toString();
parameters = parameters + "&created_on=" + current.sys_created_on.toString();
parameters = parameters + "&domain=" + current.sys_domain.toString();
parameters = parameters + "&domain_path=" + current.sys_domain_path.toString();
parameters = parameters + "&sys_ID=" + current.sys_id.toString();
parameters = parameters + "&to_profile=" + current.sys_domain.toString();
parameters = parameters + "&updates=" + current.sys_mod_count.toString();
parameters = parameters + "&updated_by=" + current.sys_updated_by.toString();
parameters = parameters + "&updated_on=" + current.sys_updated_on.toString();
request.setRequestBody(encodeURI(parameters));
var l = request.getRequestBody();
response = request.execute();
responseBody = response.haveError()
? response.getErrorMessage()
: response.getBody();
status = response.getStatusCode();
{
var gr = new GlideRecord('live_message');
gr.initialize();
gr.chat_message = current.chat_message;
gr.context = current.context.toString();
gr.formatted_message = "abc";
gr.group = current.group;
gr.has_attachments = current.has_attachments;
gr.has_links = current.has_links;
gr.has_tags = current.has_tags;
gr.id = current.id;
gr.in_reply_to = "admin";
gr.is_liked = current.is_liked;
gr.last_activity = current.last_activity;
gr.last_message = current.last_message;
gr.like_count = current.like_count;
gr.message = "abc";
gr.next_reply_order_chunk = current.next_reply_order_chunk;
gr.order = current.order;
gr.poll = current.poll;
gr.private_message = current.private_message;
gr.profile = current.profile;
gr.reflected_field = current.reflected_field;
gr.reply_to = current.reply_to;
gr.state = current.state;
gr.sys_class_name = current.sys_class_name;
gr.sys_created_by = current.sys_created_by;
gr.sys_created_on = current.sys_created_on;
gr.sys_domain = current.sys_domain;
gr.sys_domain_path = current.sys_domain_path;
gr.sys_mod_count = current.sys_mod_count;
gr.sys_updated_by = current.sys_updated_by;
gr.sys_updated_on = current.sys_updated_on;
gr.to_profile = current.to_profile;
gr.insertWithReferences();
}
} catch (ex) {
responseBody = 'Exception: ' + ex;
status = '900';
requestBody = request
? request.getRequestBody()
: null;
} finally {
gs.info("Final: Request Body: " + requestBody);
gs.info("Final: Response: " + responseBody);
gs.info("Final: HTTP Status: " + status);
gs.addInfoMessage('Final: Finished');
}
})(current, previous);
But after inserting the record it again goes back to the try block again and does the whole thing again and now with the inserted record
How is this business rule configured?
Is it possible that the changes made by this script, could also trigger the script to run?
Here's an example of what I mean:
Imagine I have a business rule that executes whenever a record in the table "u_arbitrary_counter" is updated.
Imagine that the function of this business rule is that whenever such a record is updated, we increase the value of the "u_counter" field by one, like so:
current.setValue('u_counter', parseInt(current.getValue('u_counter')) + 1);
current.update();
By using .update(), I'm forcing an update to the database, EVEN if this is a "before" business rule.
Pro Tip: Note that "before" business rules run on the data that's about to be
saved to the database, BEFORE the actual database operation has taken
place. Any changes to the "current" object in a "before" business rule
will be saved even without using current.update, because you're
modifying the data that's about to be sent to the database anyway, in
the natural course of this operation.
So using current.update() in a BEFORE business rule isn't a great idea. For the same reason though, performing any other operation which necessarily leads to a database update which could trigger this same business rule is a bad idea. It doesn't have to be current.update() -- Instead, imagine if rather than updating the current record, I did something like...
var gr = new GlideRecord('u_arbitrary_counter'); //the same table this BR is running on
gr.initialize();
gr.setValue('u_counter', parseInt(current.getValue('u_counter')) + 1);
gr.insert(); //This triggers a database action!
This is no good for the same reason.
Ditto for any REST calls which would trigger a DB action on this table which may trigger this business rule.
The solution
If this is indeed the cause of your issue (and without knowing the configuration of your business rule, I can't be sure if it is or not), there is actually a way to tell the system not to run any further business rules as a result of the operation your script performs. Right before your gr.insertWithReferences(); line (line 91), IF that block of code is the issue (which I'm fairly confident it is), add:
gr.setWorkflow(false);
This prevents business rules from running.
Unfortunately, since you're placing the record into the live_message table, that may not be a good idea either, since the messenger may require some business rule to propagate or present that information once inserted; I'm not sure.
If that is the case, I would recommend adding a condition to your business rule so that it only runs under certain circumstances, and then craft your inserted record to not meet those criteria.
Pro Tip: PS - I notice you access a table field using current.field_name.toString() in some places, and directly access
current.field_name in others. While the former is acceptable (not
that I recommend it in most cases), the latter should almost never be
used -- except in the case of journal fields. Instead, I strongly
recommend using the appropriate getter/setter methods, to avoid
pass-by-reference issues and confusion, and to ensure you're not
relying on JavaScript's coersion, which doesn't always play nice with
Mozilla Rhino, which ServiceNow runs on the back-end. Example issue
here. For more info, please see my article on using getValue()
and setValue() in ServiceNow.

Convert vbscript into rapid integration flowlanguage

I'm using Pervasive 9.2 and would like to somehow convert the vbscript into pervasives RIFL language. I want to execute the code during a Process where the f(x) component is executed to run the code. As far as the Path to the xml data, I'll be using a Macro defining where the source data is and another to save the file as well.
Here is the vbscript code below:
Set xml = CreateObject("Microsoft.XMLDOM")
xml.async = False
count_var = 1
If xml.Load("c:\folder1\test.xml") Then
For Each accounts In xml.SelectNodes("//Accounts")
For Each account In Accounts.SelectNodes("./Account")
If count_var > 1 Then
Set accountEnum = xml.createNode(1, "Account" & count_var, "")
For Each child In Account.childNodes
accountEnum.appendChild(child.cloneNode(TRUE))
Next
Accounts.replaceChild accountEnum, Account
xml.save("c:\folder1\test.xml")
else
Set accountEnum = xml.createNode(1, "Account" & count_var, "")
For Each child In Account.childNodes
accountEnum.appendChild(child.cloneNode(TRUE))
Next
Accounts.replaceChild accountEnum, Account
xml.save("c:\folder1\test.xml")
End If
count_var = count_var + 1
Next
count_var = 1
Next
End If
Set node = Nothing
Set xml = Nothing
ParseXMLFile(filepath)
documentation here
http://docs.pervasive.com/products/integration/di/rifl/wwhelp/wwhimpl/common/html/wwhelp.htm#href=ParseXMLFile_Function.html&single=true
this will return a DOMDocument Object Type
documentation here
http://docs.pervasive.com/products/integration/di/rifl/wwhelp/wwhimpl/common/html/wwhelp.htm#href=DOMDocument_Object_Type.html&single=true
hope this helps

Microsoft VBScript runtime error '800a0034' when trying to add image

I am not a coder, and am working on an old asp site, and there is a page to upload images to given page (from a dropdown list), but when I try to add images to the corresponding page I get this error, which I guess has been there since the beginning.
Microsoft VBScript runtime error '800a0034'
Bad file name or number
/path-to-file/foto.asp, line 105
The relevant code is this
'Create and Write to a File
Randomize()
strChiave = Cstr(Right(DatePart("yyyy", Date()),2))
strChiave = strChiave + Cstr(DatePart("y", Date()))
strChiave = strChiave + Replace(Time(),".","")
strChiave = strChiave + Right(Session.SessionID,4)
strChiave = strChiave + CSTR(INT(RND()*1000))
strImmagine = strChiave + Right(filename,4)
Set MyFile = ScriptObject.CreateTextFile(Application("path_public") & "/" & strImmagine)
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next
MyFile.Close
Line 105 is this
Set MyFile = ScriptObject.CreateTextFile(Application("path_public") & "/" & strImmagine)
Thank you
The Time() method returns time with such structure: HH:mm where "HH" is the hour, and "mm" the minutes. As you see, it contains a colon character, not a dot and colon is not valid inside file path.
Change this line in your code:
strChiave = strChiave + Replace(Time(),".","")
To this instead:
strChiave = strChiave + Replace(Time(),":","")

Heading image or string?

I just created a page which the user can choose the mode to show, such as icon (image) or just temperature (text). Those are my code:
<?lc
#tell the browser that we will send binary data (png)
put header("Content-type:image/png")
#get ip address
if $_GET["ip"] = "" then
put $_SERVER["REMOTE_ADDR"] into ipAddress
else
put $_GET["ip"] into ipAddress
end if
#get the mode
put $_GET["mode"] into mode
#get longtitude and latitude data
put url ("http://vo.afteroffice.com/r/v/public/pub/geoloc?ip=" & ipAddress) into geoInfo
split geoInfo by cr and ":"
#input lon and lat data into url
put url ("http://api.yr.no/weatherapi/locationforecast/1.8/?lat=" & geoInfo["latitude"] & ";lon=" & geoInfo["longtitude"]) into weatherDetail
#create tree from XML data
put revCreateXMLTree(weatherDetail, false, true, false) into tLocation
#get data about temperature and clouds
put revXMLAttribute(tLocation,"weatherdata/product/time/location/temperature", "value") into temperature
#create the output
if mode = "temperature" then
put "The temperature is " & temperature
else if mode = "icon" then
put URL("binfile:icon/hot01.png")
else if mode = "" then
put "Oke"
end if
?>
My image & text problems are:
If I don't put put header("Content-type:image/png") in my code and I call mode=icon, the result will be "‰PNG IHDRPPŽò­tEXtSoftwareAdobe ImageReadyqÉe
If I put put header("Content-type:image/png") in my code and I call mode=temperature, the result will be "Te image cannot displayed, cause it contains error"
Could you help me? Thank you.
And how about adding something like
if mode = "temperature" then
# do not put header
else if mode = "icon" then
put header("Content-type:image/png")
end if
at the position where you have your content type header now?
You just have to add the definition of mode at the beginning instead of the middle of your script

Resources