want to set a hard coded xml to message context (used js in WSO2 ESB) but getting error:
com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EvaluatorException: missing : after property id (#9) in at line number 9
function sendStubResponse(mc) {
var strFileContent = '<man:updateTSMTokenResponse xmlns:man="http://twodegreesmobile.co.nz/managetsmtoken"/>';
mc.setPayloadXML({strFileContent});
}
could you please suggest, how I can set PayloadXML in js with a variable?
<script language="js"><![CDATA[
var strFileContent = new XML(<man:updateTSMTokenResponse xmlns:man="http://twodegreesmobile.co.nz/managetsmtoken"/>);
mc.setPayloadXML(strFileContent);
]]></script>
Related
In Elm, how can I access a file on my local drive?
For example, I need to access the file:
c:\MyFolder\somefile.txt
(I'm assuming you're targeting the browser and not Node. If you want Node support, here is the documentation for it's fs module. The high-level usage will be similar to what I'm describing below for browsers.)
There is not (yet) an Elm-only API for this, so you'll have to use ports. This article is very helpful, I will adapt its example.
In short, you have to use File and FileReader API (caniuse.com), and on load of the file send the data to Elm through port. (In my example below, Elm will get a GetFile {name : String, content : String} message for every file submitted.) Here is a working example in Ellie.
Msg:
type Msg
= GetFile File
type alias File =
{ name : String
, content : String
}
Port:
port getFile : (File -> msg) -> Sub msg
(don't forget port module instead of module on top of the Elm source)
Subscription:
subscriptions : Model -> Sub Msg
subscriptions model =
getFile GetFile
HTML file input:
<input type="file" id="files" name="files[]" multiple />
JS (the main part!):
<script>
var app = Elm.Main.fullscreen();
function handleFileSelect(evt) {
var files = evt.target.files;
for (var i = 0, f; f = files[i]; i++) {
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
app.ports.getFile.send({name: theFile.name, content: e.target.result});
};
})(f);
reader.readAsDataURL(f);
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
EDIT: this example only accepts images. If you don't want that, remove the
if (!f.type.match('image.*')) {
continue;
}
part and do something different in the viewFile function (ie. don't try to interpret the content data as an image src).
Elm is now able open files as of 0.19.
Steps are as follows:
Attach an event handler to a button that sends the appropriate message to the update function.
Update function receives message and runs the file-opening function, which tells Elm runtime to ask browsers to open a file selection dialogue.
Once user action has completed, Elm runtime returns a data of type File to the update function, and the update function can decide what to do.
To read file's content, a file-reading function has to be invoked. Again, the function tells the Elm runtime to read the content of the file. The runtime again invokes your update function, this time passing the content of the file.
Please refer to this thread on Elm discourse, which includes this example on Ellie app
I'm working on a simple mail app and I need to get the body of a message. MSDN says, version 1.1 of JavaScript API for Office has body property for message object and it can be get like this:
Office.context.mailbox.item.body;
but the problem is that I need to access the body in read mode and MSDN states that:
Read mode: The body property is undefined.
Why is the body property undefined in read mode and How can I access it? (if possible)
message.body or Office.context.mailbox.item.body returns Body type. Try to use this to get body text.
Office.context.mailbox.item.body.getAsync('text', function (async) {console.log(async.value)});
Here is getBody function. it has used CoercionType type
function getBody() {
var _item = Office.context.mailbox.item;
var body = _item.body;
// Get the body asynchronous as text
body.getAsync(Office.CoercionType.Html, function (asyncResult) {
if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) {
// TODO: Handle error
}
else {
// Show data
console.log('Body', asyncResult.value.trim());
}
});
}
but above function is part of mailbox requirement set 1.3.
however this function will not work in outlook mac because it minimum mailbox requirement is 1.1
I am trying to substitute the text value in the constructor of the busyindicator with a variable rather hardcoding it. But for some reason the app is not able to understand the variable...
function wlCommonInit(){
var locale = "Caricamento";
var busyIndicator = new WL.BusyIndicator('content',{text:locale});
busyIndicator.show();
}
WL.BusyIndicator's text option expect a string, so you may not place a variable.
Instead, use WL.ClientMessages. For example:
var busy;
function wlCommonInit(){
WL.ClientMessages.loading = "טוען...";
busy = new WL.BusyIndicator();
busy.show();
}
Reading material:
Enabling Translation training module, slide #8
I was looking for a solution where I'll populate the value from one list and display it to the another list. I have now got some code but not sure how use it.
I have to now use some c# code into page source of custom newform of a list. This code will actually retrieve the user information and update to the field in the custom newform in the list.
Following C# code I want to use in newform page source using sharepoint designer
SPSite _site = SPContext.Current.Site;
ServerContext serverContext = ServerContext.GetContext(_site);
UserProfileManager myUserProfile = new UserProfileManager(serverContext);
UserProfile currentUserProfile = myUserProfile .GetUserProfile(System.Web.HttpContext.Current.User.Identity.Name);
string departmentName = (string)currentUserProfile["department"].Value;
string managerName = (string)currentUserProfile["manager"].Value;
_site.RootWeb.Dispose();
_site.Dispose();
Please help me to get this work.
SharePoint Designer removes various types of code, including all C#, in order to prevent vulnerabilities from accidentally being introduced. To use your C# code you will need to create and deploy a solution package with VIsual Studio. Instead, your best bet is probably to use JavaScript. Here is documentation for 2013, here is a utility to simplify retrieving the data in 2010, and here is some code that will get you very close to what you're trying to do.
Copy of the code in case that link dies:
<script type="text/javascript">
// ensure system stuff is loaded before we start calling client object model
ExecuteOrDelayUntilScriptLoaded(getWebUserData, "sp.js");
// create context variables
var context = null;
var web = null;
var currentUser = null;
// this function calls object model to determine current user name
function getWebUserData() {
context = new SP.ClientContext.get_current();
web = context.get_web();
currentUser = web.get_currentUser();
currentUser.retrieve();
context.load(web);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),
Function.createDelegate(this, this.onFailureMethod));
}
// this function gets called if we get current user name successfully
function onSuccessMethod(sender, args) {
var loginName = web.get_currentUser().get_loginName();
// this call requests the value for property named "Title" for current user name
GetUserProperty(loginName, "Title");
}
// yes, things failed; I ignore it here but you can display an alert
function onFailureMethod(sender, args) {
// Unable to find user profile
}
// function which retrieves the value of the property
function GetUserProperty(accountName, propertyName) {
// constructing the call to a user profile using web services
var soapMessage = '<?xml version="1.0" encoding="utf-8"?>'
+ '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
+ '<soap:Body>'
+ ' <GetUserPropertyByAccountName
xmlns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService">'
+ ' <accountName>' + accountName + '</accountName>'
+ ' <propertyName>' + propertyName + '</propertyName>'
+ ' </GetUserPropertyByAccountName>'
+ ' </soap:Body>'
+ '</soap:Envelope>'
// making a call with jQuery
$.ajax({
url: '/_vti_bin/UserProfileService.asmx',
type: "POST",
dataType: "xml",
data: soapMessage,
complete: displayProfileProperty,
contentType: "text/xml; charset=\"utf-8\""
});
return false;
}
// things went well and we get results back
function displayProfileProperty(xmlHttpRequest, status)
{
// the result is burried in XML markup so we look for the right node
$(xmlHttpRequest.responseXML).find('Values').each(function()
{
// get the text property of the node and display it
var name = $(this).find('Value').text();
alert(name);
});
}
I have implemented HTTP adapter in IBM Worklight. I want to display the result returned from server. I want to display HTML file. My code is
function getFeeds() {
var input = {
method : 'get',
returnedContentType : 'text',
path : "marketing/partners.html"
};
WL.Logger.debug("sdfsds");
return WL.Server.invokeHttp(input);
}
I want to receive(display) WL.Server.invokeHttp(input). After receiving it I want to parse the data.
Take a look at the Server-side Development Getting Started Modules. Inside the HTTP adapter – Communicating with HTTP back-end systems Module on Slide 15 - 'XSL Transformation Filtering' will show you how to filter data you get back from the backend. Further parsing and showing data has to be done on the client using onSuccess callback for WL.Client.invokeProcedure. There's a module for that too.
Here's an example of getting data and showing to a user:
var invocationData = {
adapter : 'adapter-name',
procedure : 'procedure-name',
parameters : []
};
var options = {};
options.onSuccess = function (response) {
//response is a JavaScript object
$("#id").html(response.invocationResponse.text);
}
options.onFailure = function (response) {
alert('Failed!'); //You probably want something more meaningful here.
}
WL.Client invokeProcedure(invocationData, options);
There are JavaScript libraries you can add to make searching for values inside the JSON response easier, such as: jspath and jquery-jspath. There's also XPath if you're working with XML.
If you retrieve it as plain text, once you got it back to your application, do something like
$("#container-id").html(response.invocationResponse.text);
This will inject the HTML you've retrieved to an element with id container-id.