Looking up Address field on Custom Entity in CRM 2011 - javascript

I have an entity called Customer Site from which I store Site information. From this site I create devices (another custom entity). I have created relevent address fields to those of the address entity in my customer site entity and I am trying to (based on an account) fill my site fields with those of a selected address from the account.
I referred to this article for doing so, http://xrmexpertz.com/2012/01/24/lookup-address-for-custom-entities-in-crm-2011/
I've altered the javascript and xml provided in the link to reflect my entities and my web resource.
My problem is that when i click the button that should execute the JavaScript it does nothing, and if I try to save a site without a account it sends me and error.
this is my java script.
function CustomLookup() {
'use strict';
var aoItems = getFieldValue("kez_SiteInfo_AccountId");
if (aoItems == null) {
alert(“Account is not Selected”);
return;
}
var _object = openStdDlg(“ / sfa / quotes / dlg_lookupaddress.aspx ? headerForm = 1 & parentType = 1 & parentId = ” + aoItems[0].id + “ & willCall = 0″, “LookupAddress”, 500, 330, true);
if (object) {
setFieldValue(“kez_address1_name”, object.Address.Name);
setFieldValue(“kez_address1_line1″, object.Address.Line1);
setFieldValue(“kez_address1_line2″, object.Address.Line2);
setFieldValue(“kez_address1_line3″, object.Address.Line3);
setFieldValue(“kez_address1_city”, object.Address.City);
setFieldValue(“kez_address1_province”, object.Address.StateOrProvince);
setFieldValue(“kez_address1_postalcode”, object.Address.PostalCode);
setFieldValue(“kez_address1_country”, object.Address.Country);
}
}
function setFieldValue(fieldName, fieldValue) {
Xrm.Page.getAttribute(fieldName).setValue(fieldValue);
}
This is the error is gives
Microsoft Dynamics CRM Error Report Contents
<CrmScriptErrorReport>
<ReportVersion>1.0</ReportVersion>
<ScriptErrorDetails>
<Message>Uncaught SyntaxError: Unexpected token ILLEGAL</Message>
<Line>7</Line>
<URL>/%7B634962800260003236%7D/WebResources/kez_GetLocation</URL>
<PageURL>/userdefined/edit.aspx?_gridType=10018&etc=10018&id=%7b1F8E02F0-766C-E211-934E- 00155D018211%7d&pagemode=iframe&preloadcache=1360684076423&rskey=69426415</PageURL>
<Function></Function>
<CallStack>
</CallStack>
</ScriptErrorDetails>
<ClientInformation>
<BrowserUserAgent>Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.30 (KHTML, like Gecko) Chrome/26.0.1403.0 Safari/537.30</BrowserUserAgent>
<BrowserLanguage>undefined</BrowserLanguage>
<SystemLanguage>undefined</SystemLanguage>
<UserLanguage>undefined</UserLanguage>
<ScreenResolution>1366x768</ScreenResolution>
<ClientName>Web</ClientName>
<ClientTime>2013-02-12T10:47:58</ClientTime>
</ClientInformation>
<ServerInformation>
<OrgLanguage>1033</OrgLanguage>
<OrgCulture>1033</OrgCulture>
<UserLanguage>1033</UserLanguage>
<UserCulture>1033</UserCulture>
<OrgID>{BC278BC1-EEEA-4D24-B5C6-F0720B343A1F}</OrgID>
<UserID>{D76EEA89-D760-E211-921F-00155D018211}</UserID>
<CRMVersion>5.0.9690.3236</CRMVersion>
</ServerInformation>
</CrmScriptErrorReport>

I ended up solving the problem, for one the source i listed uses quotes not recognized by CRM. Next I had to use XRM.getAttribute instead of getFieldValue.
The final and working code is below:
function CustomLookup() {
'use strict';
var aoItems = Xrm.Page.getAttribute('kez_siteinfo_accountid').getValue();
if (aoItems == null) {
alert("Account is not Selected");
return;
}
var _object = openStdDlg("/sfa/quotes/dlg_lookupaddress.aspx?headerForm=1&parentType=1&parentId=" + aoItems[0].id + "&willCall=0", "LookupAddress", 500, 330, true);
if (object) {
setFieldValue("kez_address1_name", object.Address.Name);
setFieldValue("kez_address1_line1", object.Address.Line1);
setFieldValue("kez_address1_line2", object.Address.Line2);
setFieldValue("kez_address1_line3", object.Address.Line3);
setFieldValue("kez_address1_city", object.Address.City);
setFieldValue("kez_address1_province", object.Address.StateOrProvince);
setFieldValue("kez_address1_postalcode", object.Address.PostalCode);
setFieldValue("kez_address1_country", object.Address.Country);
}
}
function setFieldValue(fieldName, fieldValue) {
Xrm.Page.getAttribute(fieldName).setValue(fieldValue);
}

Related

How can i add meeting url (session url) in generated ics file? which will appear on join button as joining link(custom event link) on teams calendar?

Right now i have added session link in description properties. I want that session link should display on join link in outlook and teams calendar. Has anybody run into the same situation?
Please let me know if i can achieve this or not ?
let descriptionLink = <div> <div> ${this.state.eventDescription}</div> <a href=${this.state.sessionLink}>Join Session</a> </div>;
let url = [
"BEGIN:VCALENDAR",
"VERSION:2.0",
"BEGIN:VEVENT",
"DTSTART:" + this.formatDate(this.state.startTime),
"DTEND:" + this.formatDate(this.state.endTime),
"SUMMARY:" + this.state.eventTitle,
"LOCATION:" + this.state.location,
"X-ALT-DESC;FMTTYPE=text/html:" + descriptionLink,
"BEGIN:VALARM",
"TRIGGER:-PT15M",
"REPEAT:1",
"DURATION:PT15M",
"ACTION:DISPLAY",
"DESCRIPTION:Reminder",
"END:VALARM",
"END:VEVENT",
"END:VCALENDAR"
].join("\n");
let blob = new Blob([url], { type: 'text/calendar;charset=utf-8' });
if (/msie\s|trident\/|edge\//i.test(window.navigator.userAgent)) {
// Open/Save link in IE and Edge
let tt: any = window.navigator;
tt.msSaveBlob(blob, 'download.ics');
} else {
// Open/Save link in Modern Browsers
window.open(encodeURI("data:text/calendar;charset=utf8," + url));
}

Apache cordova var not displayed in html

I have a problem with my application developped with angular & apache cordova on android.
On the first place I fetch the contact list from my smartphone and store it in a var : $scope.listecontacts
// alert('nb contacts '+contacts.length);
for (var i = 0; i < contacts_1.length; i++)
{
if(contacts_1[i].phoneNumbers != null && contacts_1[i].name != null && typeof contacts_1[i].phoneNumbers != 'undefined')
{
if($scope.numero_tel==0)
{
$scope.numero_tel = contacts_1[i].phoneNumbers[0].value;
}
$scope.listecontacts.push(contacts_1[i]);
}
}
And in a second time I try to display it in the html dom like this :
<div ng-repeat="t in listecontacts" >{{(t.name.formatted)}}</div>
When I launch my application it runs fine but when I go back in the home page and then go on the view that fetch the contact list, the DIV is not filled with the contact list.
I have checked the variable : $scope.listecontacts and it is not empty....
Has anyone ever meet this problem ?
Have you got any Idea ?
Thanks a lot !
I have tried to use a service this way :
app.factory('ContactService', function($window, $q, $rootScope){
var options = new ContactFindOptions();
options.filter = "";
options.multiple = true;
var filter = ["displayName", "name","phoneNumbers"];
// navigator.contacts.find(filter, onSuccess, onError, options);
return {
getContactList : function(onSuccess, onError){
navigator.contacts.find(filter,function(contacts){
$rootScope.$apply(function(){
onSuccess(contacts);
})
}, function(){
$rootScope.$apply(function(){
onError();
})
}, options)
}
}
})
And then in my controller :
$scope.get_contacts = function()
{
/*alert('get_contacts');*/
try
{
ContactService.getContactList(function(contacts)
{
But nothing chages, I check the variables with the console with via USB and Chrome and the array is fileld with thje value but the HTML doesn't displays the data.
Thanks for your help !
Actually my service was running fine I just had to change
this :
<option ng-repeat="t in listecontacts" value="{{(t.phoneNumbers[0].value)}}" >{{(t.name.formatted)}}</option>
to this
<option ng-repeat="t in listecontacts.liste_1" value="{{(t.phoneNumbers[0].value)}}" >{{(t.name.formatted)}}</option>
since I used an object instead of an array for "listecontacts"
$scope.listecontacts= {
liste_1: []
};

Angular JS some result doesn't show in Google Chrome but show in FireFox

I have created a SelectedProduct factory to save data from ProductDetailCtrl and retrieve the data in ProductOrder Ctrl
The factory is as below
.factory('SelectedProduct',function(){
var products = {};
return{
addCategory: function(_category){
return products.category = {category: _category};
},
addSelectedProduct: function(_name,_image,_quantity,_price){
return products.item = {name: _name, image: _image,quantity: _quantity,price: _price};
},
getSelectedProduct: function(){
return products.item;
},
getCategory:function(){
return products.category
}
}
})
In my product_detail.html, I save the parameter by ng-click in :
<img ng-src="{{product.image}}" alt="{{product.product_name}}" ng-click="SelectImage((detail.image = product.image),(detail.name = product.product_name),(detail.quantity = product.quantity),(detail.price = product.price))" width="500" height="340">
In ProductDetailCtrl:
SelectedProduct.addCategory($stateParams.categoryName);
$scope.SelectImage = function () {
SelectedProduct.addSelectedProduct($scope.detail.name,$scope.detail.image,$scope.detail.quantity,$scope.detail.price);
};
Then I call the saved data in product_order.html:
<h3>RM {{selectedProduct.price}}</h3>
My ProductOrderCtrl:
$scope.selectedProduct = SelectedProduct.getSelectedProduct();
var categoryName = SelectedProduct.getCategory();
BUT the output only can't show in chrome browser, it works fine in my device, and other browsers. I just wondering why would it be like this. Any idea and reason about this problem?
Note:
Other data like name, image link works fine in chrome but just the price in 00.00 format can't show. the price retrieved from MySQL online and is stored in varchar.
Result from Chrome
Result from FireFox
There must be some caching in Google Chrome, try Empty Cache and Hard Reload option which can be performed in developer mode, by a simple right click on refresh button!

AngularJS Voting System - Preventing Multi-Votes

I'm trying to create a voting system using AngularJS with the Ionic Framework. I'm using ng-repeat to loop over a series of user posts from a JSON array. Each post has an upvote and a downvote button. After one is selected, I have the button on that post disabled. The problem I'm currently experiencing is keeping that button disabled regardless if the user reopens the app. My goal is to prevent multi-voting. Currently, I'm using this method to disable the button after it's been clicked:
<button class="button button-small button-light" ng-click="upThread({{thread.id}})" ng-disabled="upDisabled[thread.id]">
<i class="icon ion-thumbsup"></i>
</button>
<button class="button button-small button-light" ng-click="downThread({{thread.id}})" ng-disabled="downDisabled[thread.id]">
<i class="icon ion-thumbsdown"></i>
</button>
$scope.upDisabled = {};
$scope.downDisabled = {};
$scope.upThread = function(id) {
...
$scope.upDisabled[id] = true;
$scope.downDisabled[id] = false;
}
$scope.downThread = function(id) {
...
$scope.downDisabled[id] = true;
$scope.upDisabled[id] = false;
}`
And this works great for disabling the buttons. Now, the problem is, I require Cache for the controller to be false, otherwise my new posts do not update in the view when added. This means, when reloading the app or switching between routes/views, the buttons become enabled again, which is not what I want. Additionally, setting cache to true doesn't keep the buttons disabled after the app has been reopened either.
I have tried using localstorage to store the $scope.upDisabled and $scope.downDisabled, but it ruins the JSON formatting. I have tried remote storage and received the same result. For example, the $scope.upDisabled and $scope.downDisabled store data like so:
{"2":true, "3":false, "4":true}
and so on. But because storing in localstorage or a database requires me to use JSON.stringify, you can guess that those quotes cause trouble and I end up with nested JSON as well. So, the data from localstorage does not return the correct format.
My known problems/options are twofold.
Is there a better solution to persistently disabling those
buttons?
How would I correctly format the JSON coming out of
localstorage?
Something else to note: Since this is a mobile/hybrid app using Ionic, I am not using cookies, but I did create a token system to act similarly.
Edit: Thanks to those who replied and your suggestions. I am currently using a MySQL database to keep track of the votes (May switch to SQLite later) #aorfevre: I've taken a look at the SQLite plugin before and will probably use it down the road. I finally got everything working how I want it to.
$scope.upDisabled = {};
$scope.downDisabled = {};
$scope.upCheck = {};
$scope.downCheck = {};
...Votes Loading function up here
...Thread loading Function up here
.finally(function(){
angular.forEach($scope.threads,function(value,index){
angular.forEach($scope.upCheck,function(value2,index){
if(value.id == value2.threadID)
{
$scope.upDisabled[value.id] = true;
$scope.downDisabled[value.id] = false;
}
})
})
angular.forEach($scope.threads,function(value,index){
angular.forEach($scope.downCheck,function(value2,index){
if(value.id == value2.threadID)
{
$scope.downDisabled[value.id] = true;
$scope.upDisabled[value.id] = false;
}
})
})
}
$scope.loadVotes();
$scope.loadThreads();
As for the server side (PHP with Laravel Framework):
public function upvoteThread($id, $token)
{
$thread = Thread::find($id);
$score = $thread->score;
$score = $score + 1;
$thread->score = $score;
$thread->save();
$voted = ThreadVote::where('threadID','=',$id)->where('token','=',$token)->get();
if($voted->isEmpty())
{
$upVote = new ThreadVote;
$upVote->threadID = $id;
$upVote->token = $token;
$upVote->upVote = 'true';
$upVote->downVote = 'false';
$upVote->save();
}
else
{
DB::table('thread_votes')
->where('threadID', '=', $id)
->where('token','=',$token)
->update(array('upVote' => 'true', 'downVote' => 'false')
);
}
return Response::json(array('status'=>1))->setCallback(Input::get('callback'));
}
public function getUpVotes($token)
{
$votes = ThreadVote::where('token','=',$token)
->where('upVote','=','true')
->select('threadID','upVote')
->get();
return Response::json($votes)->setCallback(Input::get('callback'));
}
...Similar downVote Function...
So as it stands. When the button is pushed, it saves the user's token, threadID, and vote to the database. When the view is loaded, that information, based on the token and threadID is loaded as a JSON array, associated with the Thread array and if a threadID and thread.id matches, it's pushed into the up/downdisabled scope as "threadID":bool ("1":true for example).
I'll recommand you to implement a DB if you manage huge volume of post.
I personnaly use localStorage for several preferences not for storing a db.
Therefore, if you target only for ios / android, I recommand you https://github.com/litehelpers/Cordova-sqlite-storage
If you target windows phone 8.1, the implementation is not trivial and I'm facing some issues regarding the structure of WindowsPhone & C++ compilation librairy ( more details here : https://issues.apache.org/jira/browse/CB-8866 )

How to add hidden data on Apple Push Notification

I'm using this Ruby script to send push notifications:
APNS.host = 'gateway.push.apple.com'
APNS.port = 2195
APNS.pem = 'CERTIFICATE_PATH
APNS.pass = '56895689aA'
device_token = TOKEN
APNS.send_notification(device_token, :alert => 'Message', :badge => 1, :sound => 'beep.wav')
And I'm handling it from the device like this (its Phonegap)
onAPNNotification: function (event) {
var pushNotification = window.plugins.pushNotification;
if (event.alert) {
navigator.notification.alert(event.alert);
}
if (event.badge) {
console.log("Set badge on " + pushNotification);
pushNotification.setApplicationIconBadgeNumber(this.onGCMRegisterSuccess, event.badge);
}
if (event.sound) {
var snd = new Media(event.sound);
snd.play();
}
}
Everything is working fine, I recieve the notifications, but I would like to know if there's anyway to hide data so it won't be displayed when the notification arrives (and shows an alert with some text from the notification).
Any help would be apreciated.
The payload in the example uses an aps dictionary to request that the device display an alert message with an Close button on the left and a localized title for the “action” button on the right side of the alert. In this case, “PLAY” is used as a key into the Localizable.strings file for the currently selected language to get the localized equivalent of “Play”. The aps dictionary also requests that the application icon be badged with the number 5.
{
"aps" : {
"alert" : {
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
"badge" : 5,
},
"acme1" : "bar",
"acme2" : [ "bang", "whiz" ]
}
For more info: Apple Dev

Categories

Resources