How can I pass object properties to onSyndicationSuccess event while using SMF.Net.WebClient dynamically - object

I'm trying to create a central function for dynamic web requests.
function makeWebRequest(remoteURL, requestString, callBackFunction) {
var myWebRequest = new SMF.Net.WebClient({
url : remoteURL,
httpMethod : "POST",
requestString : requestString,
requestHeaders : [
"Content-Type: application/x-www-form-urlencoded"],
onSyndicationSuccess : callBackFunction,
onServerError : function (e) {
alert(e);
}
});
myWebRequest.run(false);
}
While calling makeWebRequest, passing a callBackFunction to it like;
var remoteURL = "http://parse.com/12/test";
var requestString = "category=news&type=world";
function callBackFunction(e) {
responseText = this.responseText;
if (responseText != null) {
parsedJSON = JSON.parse(responseText);
}
}
makeWebRequest(remoteURL,requestString,callBackFunction);
Application raises an error at line
responseText = this.responseText;
How can I pass myWebRequest itself to a function like that?

I used your codeLines. I just add a textButton to Page1, and it works fine both for Android and iOS .
In Global.js;
function makeWebRequest(remoteURL, requestString, callBackFunction) {
var myWebRequest = new SMF.Net.WebClient({
url : remoteURL,
httpMethod : "POST",
requestString : requestString,
requestHeaders : [
"Content-Type: application/x-www-form-urlencoded"],
onSyndicationSuccess : callBackFunction,
onServerError : function (e) {
alert(e);
}
});
myWebRequest.run(false);
}
var remoteURL = "http://parse.com/12/test";
var requestString = "category=news&type=world";
function callBackFunction(e) {
var responseText = this.responseText;
alert(responseText);
if (responseText != null) {
parsedJSON = JSON.parse(responseText);
}
}
function Global_Events_OnStart(e) {
changeLang(Device.language, true);
include("BC.js"); //included for future BC support. Removing is not advised.
// Comment following block for navigationbar/actionbar sample. Read the JS code file for usage.
// Also there is a part of code block in Page1, which should be copied to every page for HeaderBar usage
load("HeaderBar.js");
header = new HeaderBar();
// Uncomment following block for menu sample. Read the JS code file for usage.
/*
load("Menu.js");
/**/
}
function Global_Events_OnError(e) {
switch (e.type) {
case "Server Error":
case "Size Overflow":
alert(lang.networkError);
break;
default:
SES.Analytics.eventLog("error", JSON.stringify(e));
//change the following code for desired generic error messsage
alert({
title : lang.applicationError,
message : e.message + "\n\n*" + e.sourceURL + "\n*" + e.line + "\n*" + e.stack
});
break;
}
}
In Page1.js;
function Page1_Self_OnKeyPress(e) {
if (e.keyCode === 4) {
Application.exit();
}
}
function Page1_Self_OnShow() {
//Comment following block for removing navigationbar/actionbar sample
//Copy this code block to every page onShow
header.init(this);
header.setTitle("Page1");
header.setRightItem("RItem");
header.setLeftItem();
/**/
}
function Page1_TextButton1_OnPressed(e){
makeWebRequest(remoteURL,requestString,callBackFunction);
}

it works fine. Check your makeWebRequest function, must be on Global.js. Also define "responseText" variable with "var".

Related

Unable to use variable outside of class in the class

I am making a simple note taking app to learn node and ES6. I have 3 modules - App, NotesManager and Note. I am importing the Note class into the NotesManager and am trying to instantiate it in its addNote function. The problem is that even though the import is correct, it turns out to be undefined inside the class definition. A simpler solution would be to just instantiate the NotesManager class and add the Note class to its constructor however, I want to have NotesManager as a static utility class.
Here is my code.
Note.js
class Note {
constructor(title, body) {
this.title = title;
this.body = body;
}
}
module.exports = Note;
NotesManager.js
const note = require("./Note");
console.log("Note: ", note); //shows correctly
class NotesManager {
constructor() {}
static addNote(title, body) {
const note = new note(title, body); //Fails here as note is undefined
NotesManager.notes.push(note);
}
static getNote(title) {
if (title) {
console.log(`Getting Note: ${title}`);
} else {
console.log("Please provide a legit title");
}
}
static removeNote(title) {
if (title) {
console.log(`Removing Note: ${title}`);
} else {
console.log("Please provide a legit title");
}
}
static getAll() {
//console.log("Getting all notes ", NotesManager.notes, note);
}
}
NotesManager.notes = []; //Want notes to be a static variable
module.exports.NotesManager = NotesManager;
App.js
console.log("Starting App");
const fs = require("fs"),
_ = require("lodash"),
yargs = require("yargs"),
{ NotesManager } = require("./NotesManager");
console.log(NotesManager.getAll()); //works
const command = process.argv[2],
argv = yargs.argv;
console.log(argv);
switch (command) {
case "add":
const title = argv.title || "No title given";
const body = argv.body || "";
NotesManager.addNote(title, body); //Fails here
break;
case "list":
NotesManager.getAll();
break;
case "remove":
NotesManager.removeNote(argv.title);
break;
case "read":
NotesManager.getNote(argv.title);
break;
default:
notes.getAll();
break;
}
Is it possible for me to create a strict utility class which I can use without instantiating like in Java? Pretty new here and have tried searching for it without any luck. Thank you for your help.
When you do this:
const note = new note(title, body);
you redefine note shadowing the original note from the outer scope. You need to pick a different variable name.
Something like this should work better:
static addNote(title, body) {
const some_note = new note(title, body); //Fails here as note is undefined
NotesManager.notes.push(some_note);
}

How to send a excel attachment in QCubed

This is what i am trying
$attach is the path to my excel => c:/xampp/htdocs/project/excel.xlsx
Notification::SendEmail('xyz#gmail.com', 'abc#gmail.com', "Subject","message", $attach);
If the$attach is removed then the email will go.
But it fails if i add the attachment
SendEmail function
public static function SendEmail($mixFrom, $mixTo, $strSubject, $strMessage, $mixAttachment = null, $mixCc = null, $mixBcc = null) {
// Declaration of Local Variables
$strSMTPHost = QApplication::getSettingValue(Mssetting::SMTP_HOST);
$strSMTPPort = QApplication::getSettingValue(Mssetting::SMTP_PORT);
$objMessage = Swift_Message::newInstance($strSubject, $strMessage, 'text/html');
// Set the source/destination data
$objMessage->setFrom($mixFrom);
$objMessage->setTo($mixTo);
$objMessage->setCc($mixCc);
$objMessage->setBcc($mixBcc);
// Check for attachments
if(is_array($mixAttachment)) {
foreach($mixAttachment as $strFilePath)
$objMessage->attach (Swift_Attachment::fromPath ($strFilePath));
}
elseif(is_string($mixAttachment)) {
$objMessage->attach(Swift_Attachment::fromPath($mixAttachment));
}
// Setup the transport
$objTransport = Swift_SmtpTransport::newInstance();
if($strSMTPHost) $objTransport->setHost ($strSMTPHost);
if($strSMTPPort) $objTransport->setPort($strSMTPPort);
// Setup the mailer
$objMailer = Swift_Mailer::newInstance($objTransport);
// Send the message
$objMailer->send($objMessage, $arrFailures);
if($arrFailures)
return $arrFailures;
return true;
}
I got the answer for this,
use this code:
$Attachment = $file_path; // path to your excel
Notification::SendEmail('from#abc.com',to#abc,com, "Subject", "Message", $Attachment);
in Notification.php
class Notification {
public static function SendEmail($mixFrom, $mixTo, $strSubject, $strMessage, $mixAttachment, $mixCc = null, $mixBcc = null) {
// Declaration of Local Variables
$strSMTPHost = QApplication::getSettingValue(Mssetting::SMTP_HOST);
$strSMTPPort = QApplication::getSettingValue(Mssetting::SMTP_PORT);
$objMessage = Swift_Message::newInstance($strSubject, $strMessage, 'text/html');
// Set the source/destination data
$objMessage->setFrom($mixFrom);
$objMessage->setTo($mixTo);
$objMessage->setCc($mixCc);
$objMessage->setBcc($mixBcc);
// Check for attachments
if(is_array($mixAttachment)) {
foreach($mixAttachment as $strFilePath)
$objMessage->attach (Swift_Attachment::fromPath ($strFilePath));
}
elseif(is_string($mixAttachment)) {
$objMessage->attach(Swift_Attachment::fromPath($mixAttachment));
}
// Setup the transport
$objTransport = Swift_SmtpTransport::newInstance();
if($strSMTPHost) $objTransport->setHost ($strSMTPHost);
if($strSMTPPort) $objTransport->setPort($strSMTPPort);
// Setup the mailer
$objMailer = Swift_Mailer::newInstance($objTransport);
// Send the message
$objMailer->send($objMessage, $arrFailures);
if($arrFailures)
return $arrFailures;
return true;
}
This will do the work.

Need if-else advice in actionscript3

function clickButtonHandler(event:MouseEvent):void
{
var message:Object = new Object();
message.text = txtMessage.text;
message.userName = txtUser.text;
//Posts to this swf
showMessage(message);
//Posts to ALL OTHER swf files..
group.post(message);
}
function showMessage(message:Object):void
{
output_txt.appendText(message.userName+": "+message.text + "\n");
}
function jsalertwindow(event:MouseEvent):void
{
var alert:URLRequest = new URLRequest("javascript:alert('Please enter your User name')");
navigateToURL(alert, "_self");
}
As you can see there are two function which are contain mouseevent. I want to send those function with an if-else statement. If user write something in text input component which name is txtUser and,
send_btn.addEventListener(MouseEvent.CLICK, clickButtonHandler);
will work, else(if the user forget writing anything)
send_btn.addEventListener(MouseEvent.CLICK, jsalertwindow);
will work.
And one more question should i use MouseEvent.CLICK or MouseEvent.MOUSE_DOWN? Thanks for your advice.
Assign a single handler to the button click (MouseEvent.CLICK is the right event to use) and check the field is populated in the handler:
function clickButtonHandler(event:MouseEvent):void
{
var message:Object = new Object();
// Check the field is populated
if (txtUser.text != "")
{
message.text = txtMessage.text;
message.userName = txtUser.text;
showMessage(message);
//Posts to ALL OTHER swf files..
group.post(message);
}
else
{
// Nothing in the input field, show the alert
showAlert();
}
}
function showMessage(message:Object):void
{
output_txt.appendText(message.userName+": "+message.text + "\n");
}
function showAlert():void
{
var alert:URLRequest = new URLRequest("javascript:alert('Please enter your User name')");
navigateToURL(alert, "_self");
}

Using getDocumentByKey: 'Undefined' is not a function

I'm trying to enter a notes document by using the getDocumentByUNID function. Running the following code snipped outputs an error:
var unid = (function() {
for (var x in e.row.children) {
if (e.row.children[x].content == "id") {
return e.row.children[x].text;
}
}
})();
if (!unid) {
YN.exception("Function displayGeraet: Document ID could not be found!");
} else {
var Geraete_db = app.notes_db_geraete;
YN.log("Unid: "+unid); //Output: Unid: 22EC92ED5AF33138C1257BA30053E753
YN.log("URL: "+Geraete_db.baseURL); //Output: URL: http://MT04.wd.isernhagen/HKMT/Ticket/Geraete.nsf
var Geraete_doc = Geraete_db.getDocumentbyUNID(unid); //EXCEPTION: openGeraet, TypeError: 'undefined' is not a function (evaluating 'db.getDocumentbyUNID(unid)')
Any suggestions what I'm missing?
do you have "Geraete_db.getDocumentByUNID(unid)" with "By" in uppercase or with lower case as in your code sample?
It should be getDocumentByUNID().

How to save base64 file to the client using JavaScript?

I have the gotten a certain result from the Notes tab.
The link you see inside the iframe is the name of the file.
I have the DocumentBody from the annotation in some format that looks like base64.
How do I download it?
Thanks,
Fabio
Perform a JQuery request to a URL like this
Xrm.Page.context.getServerUrl() + "XRMServices/2011/OrganizationData.svc/ActivityMimeAttachmentSet(guid'abc...')?$select=Body"
By specifying the select you will request only what you want.
Assign the result to a variable and prepend
data:application/pdf;base64,
From there you could display it inline as an HTML object or try to open it as a new window with
window.location or window.open or document.location.href
I had already the base64 documentbody string extracted like this:
function getSla() {
// Define SOAP message
var objectId;
if (typeof crmForm === "undefined") {
objectId = parent.crmForm.ObjectId;
}
else {
objectId = crmForm.ObjectId;
}
var xml =
[
"<?xml version='1.0' encoding='utf-8'?>",
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" ",
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ",
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">",
GenerateAuthenticationHeader(),
"<soap:Body>",
"<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>",
"<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' ",
"xsi:type='q1:QueryExpression'>",
"<q1:EntityName>annotation</q1:EntityName>",
"<q1:ColumnSet xsi:type='q1:AllColumns' />",
"<q1:Distinct>false</q1:Distinct><q1:Criteria><q1:FilterOperator>And</q1:FilterOperator>",
"<q1:Conditions><q1:Condition><q1:AttributeName>objectid</q1:AttributeName><q1:Operator>Equal</q1:Operator>",
"<q1:Values><q1:Value xsi:type=\"xsd:string\">",
objectId,
"</q1:Value></q1:Values></q1:Condition></q1:Conditions></q1:Criteria>",
"</query>",
"</RetrieveMultiple>",
"</soap:Body>",
"</soap:Envelope>"
].join("");
var resultXml = executeSoapRequest("RetrieveMultiple", xml);
var result = filter(resultXml.getElementsByTagName("q1:filename"), function (element) {
return /master.*sla/i.test(element.text);
});
if (result.length == 0) {
return null;
}
else {
return result[0].parentNode;
}
}
function getSlaDocumentBody(sla) {
return sla.getElementsByTagName("q1:documentbody")[0].text;
}
window.open("data:application/pdf;base64," + getSlaDocumentBody(sla));
It opened a new window with the string data:application/pdf.......... in the address bar but did nothing. I would prefer that solution indeed.
Ended up using srasmussen solution in here: http://social.microsoft.com/Forums/en/crm/thread/05134277-dd76-4fbb-8f6e-89b1a2a45af1.
var URL = serverUrl + "/userdefined/edit.aspx?etc=5&id=" + slaId;
$.get(URL, function (data) {
var WRPCTokenElement = $(data).find("[WRPCTokenUrl]");
if (WRPCTokenElement) {
var WRPCTokenUrl = WRPCTokenElement.attr("WRPCTokenUrl");
if (WRPCTokenUrl) {
URL = "/Activities/Attachment/download.aspx?AttachmentType=5&AttachmentId=" + slaId + "&IsNotesTabAttachment=undefined" + WRPCTokenUrl;
window.open(URL);
}
}
return false;
});

Resources