Getting form's parent data with ajax / javascript - javascript

In CRM DYNAMICS 2013, I'm trying to get the contents of a few text fields of a parent form, after a user opens a child form.
On the OnLoad event of the child form, I have this code:
var objvsdsassignedto = document.parentWindow.parent.parent.opener.Xrm.Page.data.entity.attributes.get("address1_line1");
The error I get is:
I have also tried:
var objvsdassignedto = window.top.opener.Xrm.Page.getAttribute("address1_line1").getValue();
The error I get is:
How do I get the contents of fields using the child form?
here's a larger version of the screenshot above: http://screencast.com/t/KHrtREYn3tL
Just wanted to update this question with more of the things I've tried:
var objvsdsassignedto = window.parent.Xrm.Page.data.entity.attributes.get("address1_line1").getValue();
var objvsdsassignedto = document.parentWindow.parent.parent.opener.Xrm.Page.data.entity.attributes.get("address1_line1");
var objvsdsassignedto = window.top.opener.Xrm.Page.getAttribute("address1_line1").getValue();
var objvsdsassignedto = parent.window.Xrm.Page.data.entity.attributes.get("address1_line1").getValue();
var objvsdsassignedto = window.parent.Xrm.Page.getAttribute("address1_composite");
var parentWindow = window.dialogArguments;
alert( parentWindow.Xrm.Page.data.entity.attributes('address1_composite').getValue());
var parentForm = window.top.opener.parent.Xrm.Page.getAttribute("address1_composite").getValue();
alert(parent.window.Xrm.Page.getAttribute('address1_line1').getValue());
var title = window.parent.opener.Xrm.page.ui.controls.getAttribute('address1_composite').getValue();
alert(title);

Are you sure that you can't do that with a simple mapping in the relationship tab? At the end of the day you are creating a lead from an account, so if you want to move a field you should be able to do that via data mapping. Open the solution go into account open the N:1 relationship node, select the relationship to lead and add the fields you want to map, It should be fairly easy without using any js.

After around 10 hours of googling, I've decided to go with cookies: http://www.quirksmode.org/js/cookies.html

Related

Unable to set Price List and Currency on Quote Via Javascript in Dynamics CRM online

I wrote some javascript that loads values of price list and currency on Quotes entity. This used to work fine in CRM Online 8.2 but since upgrade to 9.0 I have started having a weird issue.
So on OnLoad of the form the script runs and sets the values as it should. If I wait on the quote form for like 20 seconds the form auto-refreshes which I guess is a CRM functionality, but after refreshing the Price List is wiped out and I see it clears the value of my currently selected price list.
And then the user has to manually set it or refresh the page.
This is my code:
function SetCurrency()
{
var object = new Array();
object[0] = new Object();
object[0].id = "<object_id>";
object[0].name = "US Dollar";
object[0].entityType = "transactioncurrency";
Xrm.Page.getAttribute("transactioncurrencyid").setValue(object);
}
function SetPriceList() {
var object1 = new Array();
object1[0] = new Object();
object1[0].id = "<object_id>";
object1[0].name = "Default Price List";
object1[0].entityType = "pricelevel";
Xrm.Page.getAttribute("pricelevelid").setValue(object1);
}
P.S. the whole code is the same except that I removed the actual object.id's
If you are just setting the default values, I would recommend to use Business rules.
The currency can be set in user personal options, that will make sure transactioncurrencyid is auto populated in form load. Reference
On a side note, Xrm.Page is deprecated in v9 and you should be looking for code change to supported executionContext.getFormContext(). Read more

Xpages how can I compute a URL for an Xpage in the Client

I have a Xpages app that containts Tips. I send out weekly emails with links to the documents in the database. I want to be able to compute in the document the proper URL for opening these in the web, but I cannot seem to be able to do that (I need to do this as the users might be on cellphones, at home, in iNotes, etc.
var urlStr:String = "https://xxxx.xxx.com/";
var dbStr:String = "database.nsf/"
var UNID:String = document1.getDocument().getUniversalID();
urlStr = urlStr + dbStr + "0/" + UNID + "?OpenDocument"
This opens the document on the web, even though I have the form set to open in an page.
https://xxxx.xxx.com/database.nsf/xpage.xsp?action=openDocument&documentId=0858F9AC8B9E011C86257C05006E5315
This is the URL that I want to compute, but I cannot see how I can compute the name of the Xpage in the Xpage.
There has to be a way.
Trying to access the form element
Sub Querysave(Source As Notesuidocument, Continue As Variant)
Dim s As New NotesSession
Set db = s.CurrentDatabase
Set form = db.GetForm("lotusTip")
Dim xpageStr
Forall field In form.Fields
Messagebox(field)
End Forall
End Sub
Define the XPage you want to open a form with in forms properties:
This way your URL http://server/database/0/...UNID...?OpenDocument will work.
To open XPage in Notes client use notes url syntax:
notes://server/path/database.nsf/pagename.xsp?openXpage
If you're trying to identify which XPage a Form opens with, that's defined in the $XPageAlt field for web and $XPageAltClient field if you have a specific alternative XPage to open for XPiNC. You can create a NoteCollection to retrieve the Form, then access that element.
It's something we've extended in OpenNTF Domino API, with a Document.getForm() method to easily retrieve the form and a Form.getXPageAlt to retrieve the XPage name.

Reload div with same content

I've a div which contains a list of clients pulled from Mysql.
On the same page I have a jquery dialog box which pops up to allow a user to add a new client.
What I want to happen is that when the user adds a new client the containing the list reloads so the new client is available.
Is there a way to simply reload the div without using the Load() function as this is causing errors when I redeclare my classes that populate the list ?
Of course. Without looking at your code, your confusion here suggests that you don't understand "Separation of Concerns". Separate the process of getting information from the process of displaying that information. When the user enters new information, add that to javascript array or object of information you got from the server and also send that off to the server to be updated in the database. Then run the display function again using the updated information to include the new information. Ideally, the display process will use existing markup if it can, rather than deleting it all and recreating it all just to add one item. Here's a very basic example (click here). Ideally, you would take this concept and expand on it to make it optimally efficient and organized.
Here's the sample code from my jsbin. Please keep in mind this is just to get you started.
var info = [1,2,3,4,5]; //this is what you got from your ajax call to the server
function render(element, info) {
//this is a lazy system that recreates/replaces all the markup each time. I suggest doing this more efficiently, but that is work for you to do :)
var frag = document.createDocumentFragment();
var len = info.length;
for (var i=0; i<len; ++i) {
var p = document.createElement('p');
p.textContent = info[i];
frag.appendChild(p);
}
element.innerHTML = '';
element.appendChild(frag);
}
var targetElem = document.getElementById('targetElem');
render(targetElem, info);
var addButton = document.getElementById('add');
var input = document.getElementById('infoInput');
addButton.addEventListener('click', function() {
info.push(input.value); //update the information
render(targetElem, info); //render the updated information
});
Either of these should give you success.
success: function(userinfos) {
$("#users").append($('<tr><td>'+userinfos+'</td></tr>'))
display_message("user added");
}
$.ajax({
type: "GET",
url: "ht.tp://127.0.0.1:8000/result/?age="+ ageData +"&occasion="+
occasionData +"&relationship="+ forData +"#",
success: function (response) {
$("#testDIV").html(response);
}
});

Issue with creating an "old-fashioned" mail merge with Google Apps Script

This is a followup to a question I asked yesterday on the Google Apps Script Office Hours Hangout.
The goal of my final script is to create an election process for student elections at the high school where I work using Google Forms. The script has three parts: 1) Create Unique "Voting IDs" (a random 6-digit code) 2) Merge the student data (Name, Homeroom, & Voting ID) on with a template document that will create specific voting instruction for each student. (i.e. an old-fashioned mail merge) 3) Verify the results by checking Voting ID's and removing duplicate votes.
The part of the script that I am having trouble with is the student data merge (step 2). The first dataset is the only one that works. The rest show up as "DocumentBodySection". I have a feeling it is either how I am copying the text from the Document Template or how I am adding the text to the new document.
Spreadsheet w/ Data: https://docs.google.com/spreadsheet/ccc?key=0AierVcXWELCudFI1LU10RnlIVHNsUm11a0dDWEV6M1E
Document Template: (see followup comment for url)
Document Created by Script: https://docs.google.com/document/d/12r2D9SpIVmQYVaasMyMWKjHz6q-ZZyIMEBGHTwlQct8/edit
//Get Settings & Data
ss = SpreadsheetApp.getActiveSpreadsheet();
source_sheet = ss.getSheetByName("Student Data");
settings_sheet = ss.getSheetByName("SETTINGS");
results_column = settings_sheet.getRange("B19").getValue();
source_column = settings_sheet.getRange("B18").getValue();
source_lastrow = source_sheet.getLastRow();
docTemplateID = settings_sheet.getRange("B13").getValue();
docCopyName = settings_sheet.getRange("B14").getValue();
//Merge Student Data with Document
function SendDataMerge () {
// Open docTemplate and Copy Contents to entryTemplate
var docTemplate = DocumentApp.openById(docTemplateID);
var entryTemplate = docTemplate.getActiveSection();
docTemplate.saveAndClose();
// Make a NEW copy of docTemplate
var docTemplate = DocsList.getFileById(docTemplateID);
var docCopy = DocsList.copy(docTemplate, docCopyName);
var docCopyID = docCopy.getId();
// Create Array of Student Data (First, Last, Grouping, VID)
var data = source_sheet.getRange("A2:D"+source_lastrow).getValues();
// Open docCopy for Editing & Clear Contents
var doc = DocumentApp.openById(docCopyID);
var docText = doc.editAsText();
// Run through Student Data
for(var i=0; i<5 /*data.length*/; i++) { //For testing, limit this to 5 entries
var lastName = data[i][0];
var firstName = data[i][1];
var grouping = data[i][2];
var vid = data[i][3];
docText.replaceText('keyLastName', lastName);
docText.replaceText('keyFirstName', firstName);
docText.replaceText('keyGrouping', grouping);
docText.replaceText('keyVID', vid);
docText.appendText('\n*** Appended Text (End of entry) ***');
docText.appendText(entryTemplate);
}
// Save and Close
doc.saveAndClose();
}
I worked around this issue by creating a copy of the template, doing the text replacement and then appending the template elements from the original document into the copy. In particular, I used: var copyTables = templateDoc.getTables(); to fetch and store the tables (as all of my template data was contained in a table) and copyDoc.appendTable(copyTables[0].copy() ); to append the copy (the .copy() at the end seems to work the real magic). This provides the flexibility of updating the template in the friendly Documents interface without having to see a programmer.
I think the problem is with this line:
docText.appendText(entryTemplate);
The variable entryTemplate holds a DocumentBodySection, which is why you are seeing that in the output. If you are trying to append another copy of the original template text you'll need to store that before you enter the loop.
I agree with Eric that appendText(entryTemplate) isn't going to do what you want it to do.
Since you're trying to create one large document with all the students, using a "template" and replacing the text isn't going to work well. I'd suggest instead, creating the "template" in code using the api calls that produce the formatting you want. Then it makes it simple to keep appending new pages of student instructions. Although I think you may run into slowness when the document gets large... I don't know how many students you have.

Calling a dialog in Dynamics 2011 and passing multiple recordIDs to it

I want to allow the user to select one or many contacts from the contact entity, and then launch a dialog that accepts the record IDs. The idea is to add some custom configuration to the contacts.
I've currently got a custom action on a ribbon button that launches a dialog, but it only accepts one record Id. I can get access to the list of selected record Ids, thatisn't the problem, it is passing a list to the dialog using JavaScript.
I can't seem to find anything in the SDK or code snippets.
The nearest thing I found was this:
http://crmmongrel.blogspot.com/2011/06/launch-dialog-from-ribbon-button-in-crm.html
Anyone know if this is possible? I know the out of the box Send Direct E-Mail allows an email to be sent to the selected items, so I need something similar.
Should I be using dialogs or something else?
Here is a code snippet of the javascript that is called on the click of the ribbon button:
function LaunchModalDialog(SelectedControlSelectedItemReferences,dialogID, typeName)
{
// Get selected objects
var allItems = new Array
var allItems = SelectedControlSelectedItemReferences
// Just get first item for now as dialog only seems to accept one ID
var personId = allItems[0].Id;
personId = personId.replace(/\{/g, "");
personId = personId.replace(/\}/g, "");
// Load modal
var serverUri = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');
var mypath = serverUri + '?DialogID={' + dialogID + '}&EntityName=' + typeName + '&ObjectId={' +personId + '}';
mypath = encodeURI(mypath);
// First item from selected contacts only
window.showModalDialog(mypath);
// Reload form.
window.location.reload(true);
}
You'll need to specify the SelectedControlAllItemIds parameter in your Ribbon for that button. Here is a link that describes it:
http://social.microsoft.com/Forums/en/crm/thread/79f959ac-0846-472f-bff1-4f5afe692a56
--Edit--
I'm sorry, I misunderstood - you meant launch an actual CRM Dialog, not just a normal HTML pop-up dialog window.
CRM Dialogs can't be used on multiple records by design, so you aren't going to be able to use them for this.
However, you should be able to create an HTML web resource file that you can launch from the Ribbon, passing in the SelectedControlAllItemIds parameter. That HTML web resource would then have some javascript that would update the selected contacts using the REST endpoints (see the SDK for more information).
Hope that helps!

Categories