I'm using the following code to try and update a lookup field value in my CRM 2011 system from a silverlight app:
try
{
ma.my_ActionDetails = details;
Guid userId = new Guid();
foreach (SystemUser s in SystemUsers)
{
if (s.FullName.Equals(comboBox1.SelectedItem))
{
userId = s.SystemUserId;
}
}
// Define eval statements for setting lookup to a value and null
string setLookupJscript = #"Xrm.Page.getAttribute(""{0}"").setValue([ {{ id: ""{1:B}"", typename: ""{2}"", name: ""{3}"" }}])";
string evalStatement = null;
// Set the statement to be evaluated based upon the value of the id argument
// Setting the lookup to a value
evalStatement = string.Format(setLookupJscript, "my_salesperson", userId, "my_memberaction", ma.my_SalesPerson.Name);
HtmlPage.Window.Eval(evalStatement);
_context.UpdateObject(ma);
_context.BeginSaveChanges(OnUpdateAccountComplete, ma);
}
catch (SystemException se)
{
_syncContext.Send(new SendOrPostCallback(showErrorDetails), se);
}
However when I run this code it generates the following errors:
In the browser:
'Xrm' is undefined
From the code:
System.InvalidOperationException: [Common_MethodFailed]
Can anyone explain whats going on here?
Thanks,
Jack
You need to be within the context of a CRM form for the Xrm namespace to be available. Are you running from within a form?
From the CRM SDK:
If your Silverlight web resource is designed to be viewed in an entity form, the form has an Xrm.Page.context object you can use to access contextual information.
If you need your Silverlight application to appear outside the context of the form you must configure an HTML web resource to provide this context information by adding a reference to the ClientGlobalContext.js.aspx page. After this reference is added, your Silverlight application can access contextual information in the same way it can in an entity form. The following sample shows how to call the getServerUrl function from the Xrm.Page.context object.
private string serverUrl = "";
ScriptObject xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");
ScriptObject page = (ScriptObject)xrm.GetProperty("Page");
ScriptObject pageContext = (ScriptObject)page.GetProperty("context");
serverUrl = (string)pageContext.Invoke("getServerUrl");
Related
We need to add service information like officeId for entities.
Or how we can use IntuitAnyType for set and get our service information. I tried to add xmlElement into IntuitAnyType, and then create bill, but when I try to get this bill, IntuitAnyType field (BillEx) was null. Also I tried to add NumberTypeCustomFieldDefinition and got Validation Exception was thrown.Details:Operation Could not find resource for relative : /v3/company/4620816365019493550/numbertypecustomfielddefinition of full path: https://c50.sandbox.qbo.intuit.com/qbo50/v3/company/xxxxxxxxxxx/numbertypecustomfielddefinition?minorversion=29&requestid=a52a148d0f6f4c3ab366f55ca7440525 is not supported..
var dataService = new DataService(_serviceContext);
var officeId= new QBO.NumberTypeCustomFieldDefinition()
{
DefaultValue = 0,
DefaultValueSpecified = true,
Name = "OfficeId",
Hidden = true,
EntityType = QBO.objectNameEnumType.Bill.ToString(),
Required = false
};
var createdCaseIdField = dataService.Add(caseId);
is it possible?
Is there a way to create and update hidden custom field for bill with use api
No. Custom fields can only be created via the UI, and they are visible in the UI.
This is all documented here:
https://developer.intuit.com/app/developer/qbo/docs/develop/tutorials/create-custom-fields#enable-custom-fields
I need to access a specific property inside a COM object (the iTunes COM Library). You can access this property with the dynamic view of the Visual Studio debugger.
I tried to get this property using Reflection but I don't get any private properties or fields back.
I can access all the Properties that I also see in the debugger using this line:
new Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView(myObject).Items
However, I would rather not use this call because I believe an easier solution exists.
If you have iTunes installed this would be a simple example of what I'm trying to achieve:
iTunesAppClass app;
if (Process.GetProcessesByName("iTunes").Any())
{
app = new iTunesAppClass();
}
else
{
return;
}
foreach (IITPlaylist playlist in app.LibrarySource.Playlists)
{
// This does not work. There is no "Parent".
//var parent = playlist.Parent;
Type playListType = playlist.GetType();
// both contain 0 results
var fields = playListType.GetFields(BindingFlags.NonPublic);
var properties = playListType.GetFields(BindingFlags.NonPublic);
// works but only during runtime
//var parent2 = new Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView(playlist).Items[4];
}
I am using stripe connect(destination payment) with the help of stripe.net library from Jaymedavis.
The problem that I am facing is that I am not able to retrieve the destination payment ID to update the metadata in the connected account. The following line returns a null preventing me from updating meta data on the connected account. But the strange thing is that when I log in to the dashboard the destination payment ID exists. I am not sure why I am not able to retreive it in code.
Is the charge creation asynchronous?. I am not sure. Stripe's connect documentation does not help either. The following line returns a null. My code is down below. Seeking help.
String deschargeID = result.Transfer.DestinationPayment;
Here is the code that I am using
var service = new StripeChargeService(ZambreroSecretKey);
var result = (Stripe.StripeCharge) null;
try {
result = service.Create(newCharge);
if (result.Paid) {
//get the chargeID on the newgen account and update the metadata.
//Returns null even though it exists in the dashboard
String deschargeID = result.Transfer.DestinationPayment;
var chargeService = new StripeChargeService(newgenSecretKey);
StripeCharge charge = chargeService.Get(deschargeID);
charge.Metadata = myDict;
Response.Redirect("PgeCustSuccess.aspx?OrderID=" + OrderID);
}
} catch (StripeException stripeException) {
Debug.WriteLine(stripeException.Message);
stripe.Text = stripeException.Message;
}
The charge object's transfer attribute is not expanded by default, meaning it's just a string with the ID of the transfer object ("tr_..."), not a full transfer object.
According to Stripe.net's documentation, you can expand the transfer attribute by adding this line:
service.ExpandTransfer = True
before sending the charge creation request.
What is the best way to access Microsoft Access Database object's Properties (like in CurrentDb.Properties) from C# in Visual Studio 2010?
(Not essential: In fact I want to get rid of Replication in a few dozen databases "on demand". Replication is not in use for a few years, and it was OK for MS Access prior to 2013. Access 2013 rejects databases with this feature.)
You can iterate over and modify the properties in the Access database by using the Access DAO object library.
The following code iterates over the properties in the database as well over the different containers and its properties as well over the Documents and its properties in the Databases container. The output is written to the Debug Output window.
After that I pick a Property from different property collections and change it's value. Do note that using the indexer on the collection will throw an exception if the property doesn't exist.
Make sure you have a reference to the Primary Interop Assembly for Microsoft Office 12.0 Access database engine Object Library (your version migth vary) so that you can have the following in your using statements:
using Microsoft.Office.Interop.Access.Dao;
Your method would go like this:
// Open a database
var dbe = new DBEngine();
var db = dbe.OpenDatabase(#"C:\full\path\to\your\db\scratch.accdb");
// Show database properties
DumpProperties(db.Properties);
// show all containers
foreach (Container c in db.Containers)
{
Debug.WriteLine("{0}:{1}", c.Name, c.Owner);
DumpProperties(c.Properties);
}
//Show documents and properties for a specific container
foreach (Document d in db.Containers["Databases"].Documents)
{
Debug.WriteLine("--------- " + d.Name);
DumpProperties(d.Properties);
}
// set a property on the Database
Property prop = db.
Properties["NavPane Width"];
prop.Value = 300;
// set a property on the UserDefined document
Property userdefProp = db
.Containers["Databases"]
.Documents["UserDefined"]
.Properties["ReplicateProject"];
userdefProp.Value = true;
Property dumper helper
private static void DumpProperties(Properties props)
{
foreach (Property p in props)
{
object val = null;
try
{
val = (object)p.Value;
}
catch (Exception e)
{
val = e.Message;
}
Debug.WriteLine(
"{0} ({2}) = {1}",
p.Name,
val,
(DataTypeEnum) p.Type);
}
}
I used this to overcome an exception being thrown on dynamic types (as the Value property turns out to be)
My project requires me to programmatically access TFS servers we don't administer and to get real time information about the fields in the WorkItemTypes. I can get the field names and most of the information I need by looking at the FieldDefinition in the WorkItemType's FieldDefinitions collection.
public WitType(WorkItemType type)
{
this.Fields = new List<string>();
foreach (FieldDefinition f in type.FieldDefinitions)
{
Fields.Add(f.Name);
}
}
One thing missing is the IsRequired property. I need to be able to tell if a field is required.
I have tried running a work item story query
WorkItemCollection workItemCollection = workItemStore.Query
foreach (WorkItem workItem in workItemCollection)
foreach (Field field in workItem.Fields)
{
textBox1.Text += field.Name + " is required? " + field.IsRequired.ToString();
}
and then checking the IsRequired property of the Field item in the WorkItem's Fields collection.
Only problem is that for a given work item type one work item says Title is required, then the next work item will have the IsRequired property = false.
Is there a way to determine if a WorkItem field is required without resorting to the WIT xml file? If not, is there a way to programmatically access the WIT xml file?
I needed to perform a similar task, and the following was the only way I could figure out how to accomplish it.
As mentioned by others, WorkItem validation is defined in the WorkItemType's template. Fields can have different validation requirements based on the WorkItem's current state and even the current user's permissions.
Therefore, you need to create/retrieve a WorkItem instance using the user's credentials. If your application is impersonating the current user (i.e. in an ASP.NET application using Windows Authentication and impersonation), then you can simply use Option 1, where you use the TFS API to get the WorkItem, without impersonating.
If you're application is not impersonating the user, when you can use Option 2, where you use the TFS impersonation feature, to make calls on-behave of a user. This requires granting the "Make Requests on behave of others" permission in TFS to the application's identity (i.e. in ASP.NET the application pool's identity). See the following link for more information:
http://blogs.microsoft.co.il/blogs/shair/archive/2010/08/23/tfs-api-part-29-tfs-impersonation.aspx
The following code is an example on how to do Option 1 and Option 2.
// Set the following variables accordingly
string workItemTypeName = "Bug";
string teamProjectName = "My Project";
string usernameToImpersonate = "joesmith";
string tfsTeamProjectCollectionUrl = "http://mydomain.com:8080/tfs/ProjectCollectionName";
// OPTION 1: no impersonation.
// Get an instance to TFS using the current thread's identity.
// NOTE: The current thread's identity needs to have the "" permision or else you will receive
// a runtime SOAP exception: "Access Denied: [username] needs the following permission(s) to perform this action: Make requests on behalf of others"
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection( new Uri( tfsTeamProjectCollectionUrl ) );
IIdentityManagementService identityManagementService = tfs.GetService<IIdentityManagementService>();
// OPTION 2: impersonation. Remove the following two lines of code if you don't need to impersonate.
// Get an instance to TFS impersonating the specified user.
// NOTE: This is not needed if the current thread's identity is that of the user
// needed to impersonate. Simple use the ablve TfsTeamProjectCollection instance
TeamFoundationIdentity identity = identityManagementService.ReadIdentity( IdentitySearchFactor.AccountName, usernameToImpersonate, MembershipQuery.None, ReadIdentityOptions.None );
tfs = new TfsTeamProjectCollection( tfs.Uri, identity.Descriptor );
WorkItem workItem = null;
WorkItemStore store = tfs.GetService<WorkItemStore>();
// Determine if we are creating a new WorkItem or loading an existing WorkItem.
if( workItemId.HasValue ) {
workItem = store.GetWorkItem( workItemId.Value );
}
else {
Project project = store.Projects[ teamProjectName ];
WorkItemType workItemType = project.WorkItemTypes[ workItemTypeName ];
workItem = new WorkItem( workItemType );
}
if( workItem != null ) {
foreach( Field field in workItem.Fields ) {
if( field.IsRequired ) {
// TODO
}
}
}