How do I call these web services in google script? - javascript

I've spent tens of hours on it: calling a web service from my school platform with google script. It works in php but not in google script. I don't know how to implement the "getClassList" method in the script. Everything tried nothing works! Please help me before I go completely crazy!
I give you everything I think is necessary to write the script:
Webservices V3 (SOAP)
URL's:
https://tisj-bilzen.smartschool.be/Webservices/V3
https://tisj-bilzen.smartschool.be/Webservices/V3?wsdl
Details of the methode:
getClassList
This method requests a list of all classes. This method provides a serialized array with the class name, description, visibility, and unique class code.
string $accesscode: Password webservices
getClassListJson
This method requests a list of all classes. This method provides a JSON array with the class name, description, visibility and unique class code.
string $accesscode: Password webservices
Password webservices : 408cb6c31db39698b176
Many thanks in advance !!
Patrick Crijns
one of my attempts :
function probeer5(){
var $code = '408cb6c31db39698b176';
var options = {"headers" : {"Authorization" : "accesscode:408cb6c31db39698b176>"} };
var url = "https://tisj-bilzen.smartschool.be/Webservices/V3?wsdl#getClassList";
var response = UrlFetchApp.fetch(url,options);
var result= response.getContentText();
Logger.log(result);
}

I'm trying to do the same thin on my school's smartschool.be-platform. Did you ever get this to work?
I've tried setting up a soap client like in this example!, but didn't get it to work for smartschool...
Update: I got it to work! Check out the demo code bolow, for the saveUserParameter method. I'm sure you'll be able to alter it to get the getClassList method to work as well. Don't forget to change my school prefix (msvoskenslaan) to yours (tisj-bilzen)!
function SS() {
var SSpass = "MySecretPassWord" //webservices PW
var sam = "fake.student" //user identifier (login or uniek ID)
var parameter = "extraInfo" //as this script calls the saveUserParameter webservice, this is the name of the parameter field which will be altered
var data = "Door script ingevoerde waarde met spaties \nen \nline \nbreaks." //the data entered in the field mentioned above
var xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="https://msvoskenslaan.smartschool.be:443/Webservices/V3" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ><SOAP-ENV:Body><mns:saveUserParameter xmlns:mns="https://msvoskenslaan.smartschool.be:443/Webservices/V3" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><accesscode xsi:type="xsd:string">' + SSpass + '</accesscode><userIdentifier xsi:type="xsd:string">' + sam + '</userIdentifier><paramName xsi:type="xsd:string">' + parameter + '</paramName><paramValue xsi:type="xsd:string">' + data + '</paramValue></mns:saveUserParameter></SOAP-ENV:Body></SOAP-ENV:Envelope>'
var options =
{
"method" : "post",
"contentType" : "text/xml; charset=utf-8",
"payload" : xml,
"muteHttpExceptions" : true
};
var soapCall= UrlFetchApp.fetch("https://msvoskenslaan.smartschool.be/Webservices/V3", options);
Logger.log(soapCall);
}

Related

SuiteScript Create File In Client Side Script

I'm trying to create a file in the File Cabinet and write to it in a Client Script. Checking the API reference, I see that all the File objects are Server-side only.
Does that mean you can't create and write to a file in a Client script? I tried to use the code in my Client script anyway, but got the error:
Fail to evaluate script: {"type":"error.SuiteScriptModuleLoaderError","name":"{stack=[Ljava.lang.Object;#59c89ae9, toJSON=org.mozilla.javascript.InterpretedFunction#5a4dd71f, name=MODULE_DOES_NOT_EXIST, toString=org.mozilla.javascript.InterpretedFunction#1818dc3c, id=, message=Module does not exist: N/file.js, TYPE=error.SuiteScriptModuleLoaderError}","message":"","stack":[]}
When I tried to save it in NetSuite as the script file. Does the above mean that the N/File object can't be loaded in a Client script?
Can I write to a file in a Client script?
Create a Client Script - this Script will contain the function to call the Suitelet and pass along information from the current record/session if needed.
function pageInit{
//required but can be empty
}
function CallforSuitelet(){
var record = currentRecord.get();
var recId = record.id;
var recType = record.type
var suiteletURL = url.resolveScript({
scriptId:'customscriptcase3783737_suitelet',// script ID of your Suitelet
deploymentId: 'customdeploycase3783737_suitelet_dep',//deployment ID of your Suitelet
params: {
'recId':recId,
'recType':recType
}
});
document.location=suiteletURL;
}
return {
CallforSuitelet : CallforSuitelet,
pageInit : pageInit
}
Create a Suitelet - this script will create the file
function onRequest(context) {
var requestparam = context.request.parameters;
var recId = requestparam.recId; //the same name of the fields specified in url.resolveScript parameters from Client Script
var recType = requestparam.recType;
var objRecord = record.load({
type: record.Type.___,//insert record type
id: recId
});
var content = 'Insert Content Here';
var xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE pdf PUBLIC \"-//big.faceless.org//report\" \"report-1.1.dtd\">\n";
xml += "<pdf>\n<body font-size=\"12\">\n<h3>Sample PDF</h3>\n";
xml += "<p></p>";
xml += content;
xml += "</body>\n</pdf>";
context.response.renderPdf({xmlString: xml});
}
return {
onRequest: onRequest
}
As you've already discovered, server-only modules can't be called from client-side scripts directly, but this can be done via a Suitelet. You will need to decide how the Suitelet does it's work. An example of the principal at work can be found here and here

Request failed SOAP WS returned code 404

I want to consume the following soap url:
http://89.221.253.174:8080/OpenClinica-ws/ws/data/v1/dataWsdl.wsdl
I am using google pass script and my code looks as below:
var xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v1=\"http://openclinica.org/ws/studySubject/v1\" xmlns:bean=\"http://openclinica.org/ws/beans\">"
+"<soapenv:Header>"
+"<wsse:Security soapenv:mustUnderstand=\"1\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
+"<wsse:UsernameToken wsu:Id=\"UsernameToken-27777511\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"
+"<wsse:Username>x</wsse:Username>"
+"<wsse:Password>y</wsse:Password>"
+"</wsse:UsernameToken>"
+"</wsse:Security>"
+"</soapenv:Header>"
+"<soapenv:Body>"
+"<v1:importRequest>"
+"<ODM>"
+"<ClinicalData StudyOID=\"S_PROSPER2\" MetaDataVersionOID=\"v1.0.0\">"
+"<SubjectData SubjectKey=\"SS_UU001\">"
+"<StudyEventData StudyEventOID=\"SE_QUESW4\" StudyEventRepeatKey=\"0\">"
+"<FormData FormOID=\"F_RANDANDQUEST_11\">"
+"<ItemGroupData ItemGroupOID=\"IG_RANDA_UNGROUPED\" ItemGroupRepeatKey=\"1\" TransactionType=\"Insert\">"
+"<ItemData ItemOID=\"I_RANDA_RAND01\" Value=\"1\"/>"
+"<ItemData ItemOID=\"I_RANDA_RAND02\" Value=\"1\"/>"
+"<ItemData ItemOID=\"I_RANDA_RAND03\" Value=\"1\"/>"
+"<ItemData ItemOID=\"I_RANDA_RAND04\" Value=\"1\"/>"
+"</ItemGroupData>"
+"</FormData>"
+"</StudyEventData>"
+"</SubjectData>"
+"</ClinicalData>"
+"</ODM>"
+"</v1:importRequest>"
+"</soapenv:Body>"
+"</soapenv:Envelope>";
var options =
{
"method" : "post",
"contentType" : "text/xml; charset=utf-8",
"payload" : xml
};
var result = UrlFetchApp.fetch("http://89.221.253.174:8080/OpenClinica-ws/ws/data/v1/dataWsdl.wsdl", options);
Logger.log(result);
I don't know actually what is the error on here, what does 404 means in this case? Seems like I am communicating with the server but something else is missing.
Any idea what would be wrong in here?
PS: The same code works just fine using soapUI.
solved it by puting all the xml in one line this way:
var xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v1=\"http://openclinica.org/ws/data/v1\"><soapenv:Header><wsse:Security soapenv:mustUnderstand=\"1\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><wsse:UsernameToken wsu:Id=\"UsernameToken-27777511\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"><wsse:Username>x</wsse:Username><wsse:Password>y</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><v1:importRequest><ODM><ClinicalData StudyOID=\"S_PROSPER2\" MetaDataVersionOID=\"v1.3.0\"><SubjectData SubjectKey=\"SS_UU001\"><StudyEventData StudyEventOID=\"SE_QUESW4\" StudyEventRepeatKey=\"0\"><FormData FormOID=\"F_RANDANDQUEST_11\"><ItemGroupData ItemGroupOID=\"IG_RANDA_UNGROUPED\" ItemGroupRepeatKey=\"1\" TransactionType=\"Insert\"><ItemData ItemOID=\"I_RANDA_RAND01\" Value=\"1\"/></ItemGroupData></FormData></StudyEventData></SubjectData></ClinicalData></ODM></v1:importRequest></soapenv:Body></soapenv:Envelope>";
I have no idea why is this way it works, but it is working!

Lost on AJAX to .ASP file

I have a need to automate data collection for users who visit specific pages of my site. To do this, I'm querying the LDAP. The LDAP query works just fine when I double click on the file locally (.vbs). However, when I double click on it while it's on the server, it doesn't work (as would be expected). However, I'm as new as new can get to writing VBScript.
After reading a few articles I modified the code and changed the extension to .asp. I ended up with this:
<%
On Error Resume Next
'Create the Array that will be passed
Dim employee(7)
'Employee System Related Info
Set objSysInfo = CreateObject("ADSystemInfo")
employee(0) = objSysInfo.SiteName
'Employee specific information
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
employee(1) = objUser.sAMAccountName
employee(2) = objUser.givenName
employee(3) = objUser.sn
employee(4) = objUser.displayName
employee(5) = objUser.telephoneNumber
employee(6) = objUser.title
Return employee
%>
In the JavaScript function which would call this .asp file via ajax, I am able to get the employee number which I think could be received by the .asp file and do the rest of the query.... However, I'm not even sure if I'm returning everything correctly in the VBScript. Furthermore, I'm not even sure if I should be using a GET or POST AJAX call. Can someone point me in the right direction?
Updated 03/22/2017 at 10AM CDT
I've finally gotten back to the office and tried to play around. I'm still a little lost. I've made some updates to the code below you'll see the javascript and the VBScript
FIRST the JavaScript:
var employee = {};
function getEmp() {
var ldapUserName = ADSystem.UserName;
$.ajax({
type: "POST",
data: ldapUserName,
url: "https://here.is.my/url.asp",
success: $.ajax({
type: "GET",
dataType: "json",
success: function(responseText) {
employee = responseText;
},
error: function() {
alert("No Data Received");
}
}),
error: function() {
alert("Connection Failed");
}
});
}
Now here is the updated VBScript based on a few things I read and the suggestions from here:
<%
Public Function empDemo(username)
On Error Resume Next
'Create the Array that will be passed
Dim employee(7)
'Employee System Related Info
Set objSysInfo = CreateObject("ADSystemInfo")
employee(0) = objSysInfo.SiteName
'Employee specific information
strUser = objSysInfo.username
Set objUser = GetObject("LDAP://" & strUser)
employee(1) = objUser.sAMAccountName
employee(2) = objUser.givenName
employee(3) = objUser.sn
employee(4) = objUser.displayName
employee(5) = objUser.telephoneNumber
employee(6) = objUser.title
response.write "{ site: " & employee(0) & ","
& "empNum: " & employee(1) & ","
& "empFName: " & employee(2) & ","
& "empLName: " & employee(3) & ","
& "empFullName: " & employee(4) & ","
& "empExt: " & employee(5) & ","
& "empTitle: " & employee(6) & "}"
End Function
%>
Currently, I'm getting the alert stating "No Data Received". What am I doing wrong?
Instead of "return Employee", have you tried:
response.write employee
or maybe
response.write employee.sAMAccountName
Is this VB6? Not sure what libraries are available in classic asp, so you might have to manually write the data in JSON form... i.e...
response.write "{ name: " & employee.sAMAccountName & "}"

Form Information to Appear On Another Page

I am trying to create a form that, once submitted, will be sent to my index.html page for other users to view. I want it so multiple users anywhere in the world can submit information and so the website displays all their information at once.
Here is my submit page's PHP code:
<form action="submit_a_message.php" method="post">
<textarea name="message" cols="60" rows="10" maxlength="500"></textarea><br>
<input type="submit">
</form>
I am trying to figure out how to make the information submited via that form appear on my index.html page. This is the code I found online, but it doesn't work. Why?
<?php>
string file_get_contents ( string $submit_a_message.php [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )
<?>
Any help would be greatly appreciated.
To make submitted text avaliable on your index page, you need a place where you would store it. You can use MySQL base to do that, or (if you can't or you really don't want) you can use text file with your texts/posts (that is not really good way, i warned you).
To do that with MySQL you can use a code like this on your submit_a_message.php:
<?php
//connection to database and stuff
...
if $_POST['message'] {
$message = $_POST['message'];
$sql = "insert into `mytable` values $message"; //that is SQL request that inserts message into database
mysql_query($sql) or die(mysql_error()); // run that SQL or show an error
}
?>
In order to show desired vaues from table use above-like idea, your SQL request would be like select * from mytable where id = 123
if your not married to the idea of using php and learning how to manage and access a database you could use jquery and a trird party backend like parse.com
If your new to storing and retrieving data, I would definately reccomend the services that https://parse.com/ offeres. It makes storing and retrieving data trivial. Best of all, the service is free unless your app makes more than 30 API requests per second. I have an app that 61 users use daily and we have never come close to the 30 req per second limit.
To save your info, you could write:
$('document').ready(function(){
$('#submit_btn').on('click',function(){ // detect button click, need to add "submit_btn" as the id for your button
var Message = Parse.Object.extend("Message"); //create a reference to your class
var newObject = new EventInfo(); //create a new instance of your class
newObject.set("messageText", $("#myMessage").val()); //set some properties on the object, your input will need the id "myMessage"
newObject.save(null, { //save the new object
success: function(returnedObject) {
console.log('New object created with objectId: ' + returnedObject.id);
},
error: function(returnedObject, error) {
console.log('Failed to create new object, with error code: ' + error.message);
}
});
});
});
Retrieving that info later would be as easy as:
var Message = Parse.Object.extend("Message"); //create a reference to your class
var query = new Parse.Query(Message); //create a query to get stored objects with this class
query.find({
success: function(results) { //"results" is an array, you can fine tune your queries to retrieve specific saved objects too
for (var i = 0; i < results.length; i++) {
var object = results[i];
$(body).append("Message #" + (i+1) + object.get("messageText");
}
},
error: function(error) {
console.log("Failed to complete Query - Error: " + error.code + " " + error.message);
}
});

Response Email Activity Images in CRM 2011

How can I preserve images in a response to an email activity?
The images in the email show when viewed in CRM - they are added as attachments. When I click the 'respond' button, write a response, and send the response the images are stripped from the email and are not attached to the email.
I have been trying all sorts of things with JScript .
I would rather not have to write anything other than JScript.
This is possible with javascript. I don't know what you tried but this can be done. I.e. catch the send event of your form and create the attachment with Javascript.
Other options are:
You could use a workflow to attach the note of the parent email to
the response. But then you will be forced to save your email wait a
little while (execution of the workflow) and then send the email.
Write plug-in code (but you won't use anything else but Javascript
Javascript to delete attachment:
function deleteAttachments(){
var notesId = {GUID of notes};
var objNotes = new Object();
objNotes.DocumentBody = null;
objNotes.FileName = null;
objNotes.FileSize = null;
objNotes.IsDocument = false;
updateRecord(notesId, objNotes, “AnnotationSet”);
}
function updateRecord(id, entityObject, odataSetName) {
var jsonEntity = window.JSON.stringify(entityObject);
var serverUrl = Xrm.Page.context.getServerUrl();
var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;
var updateRecordReq = new XMLHttpRequest();
var ODataPath = serverUrl + ODATA_ENDPOINT;
updateRecordReq.open(‘POST’, ODataPath + “/” + odataSetName + “(guid’” + id + “‘)”, false);
updateRecordReq.setRequestHeader(“Accept”, “application/json”);
updateRecordReq.setRequestHeader(“Content-Type”, “application/json; charset=utf-8″);
updateRecordReq.setRequestHeader(“X-HTTP-Method”, “MERGE”);
updateRecordReq.send(jsonEntity);
}
I can access the attachments here: https:{org. URL}/xrmServices/2011/OrganizationData.svc/EmailSet(guid'3848cb4d-673f-e211-b9af-005056bd0001')/email_activity_mime_attachment
guid is the guid of the email.
The image is stored in d:Body as Base64.
Now all I need to do is rewrite img for each inline image with src="data:image/png;base64,theverylongstring...
All inline images will be preserved in the response as Base64.

Categories

Resources