I am Trying to launch the detail page of directory contacts(Some organigation contacts) with contact id. for local contacts it is working fine but not working for organigation contacts.
Here is my code. (name is contact name ,idstr is directory id )
lookupByName = ContactsContract.Contacts.CONTENT_FILTER_URI.buildUpon().appendEncodedPath(name)
.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, idStr).build();
mCursor = mContext.getContentResolver().query(lookupByName, new String[]{ContactsContract.PhoneLookup.DISPLAY_NAME, ContactsContract.PhoneLookup._ID}, null, null, null);
if (mCursor.moveToFirst()) {
idPhone =
Long.valueOf(mCursor.getString(
mCursor.getColumnIndex(ContactsContract.PhoneLookup._ID)));
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(ContentUris.
withAppendedId(ContactsContract.Contacts.CONTENT_URI, idPhone ));
startActivity(intent);
Please help me.
Thanks in advance.
This is tricky, but managed to get it working
You need to get the contact's LOOKUP_KEY, build a LookupUri from it, append the DIRECTORY_PARAM_KEY to the LookupUri, and put that in the intent's setData.
String name = "hello";
String directoryId = "5"
Uri uri = Contacts.CONTENT_FILTER_URI.buildUpon().appendPath(name).appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, directoryId).build();
String[] projection = new String[]{Contacts._ID, Contacts.DISPLAY_NAME, Contacts.LOOKUP_KEY};
Cursor cur = getContentResolver().query(uri, projection, null, null, null);
DatabaseUtils.dumpCursor(cur); // debug
// add some safety checks first obviously...
cur.moveToFirst();
String lookup = cur.getString(2);
Uri lookupUri = Contacts.getLookupUri(cur.getLong(0), lookup).buildUpon().appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, directoryId).build();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(lookupUri);
startActivity(intent);
Related
On CRM 2013 on-premise, I'm trying to write a plugin that triggers when an update is made to a field on Quote. The plugin then creates a new custom entity "new_contract".
My plugin is successfully triggered when the update to that field is made. However I keep getting an error message "The given key was not present in the dictionary" when trying to create the new custom entity.
I'm using a "PostImage" in this code. I confirm that it's registered using the same name in Plugin Registration.
Here is the code
var targetEntity = context.GetParameterCollection<Entity>
(context.InputParameters, "Target");
if (targetEntity == null)
{throw new InvalidPluginExecutionException(OperationStatus.Failed,
"Target Entity cannot be null")}
var postImage = context.PostEntityImages["PostImage"];
if (postImage == null)
{throw new InvalidPluginExecutionException(OperationStatus.Failed,
"Post Image is required");}
var quote = context.GenerateCompositeEntity(targetEntity, postImage);
//throw new InvalidPluginExecutionException(OperationStatus.Failed, "Update is captured");
//Guid QuoteId = (Guid)quote.Attributes["quoteid"];
var serviceFactory = (IOrganizationServiceFactory)serviceProvider
.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);
var contractEntity = new Entity();
contractEntity = new Entity("new_contract");
if (quote.Attributes.Contains("portfolio"))
{
var quotePortfolio = (EntityReference)quote.Attributes["new_portfolio];
contractEntity[Schema.new_contract.PortfolioName] =
new EntityReference(quotePortfolio.LogicalName, quotePortfolio.Id);
}
if (quote.Attributes.Contains(Schema.Quote.QuoteName))
{
var quoteName = (string)quote.Attributes["name"];
contractEntity[Schema.new_contract.contractName] = quoteName;
}
var contractId = service.Create(contractEntity);
I think context does not contain "PostImage" attribute.You should check context to see whether it contains the attribute before getting the data.
Looking at this line in your post above:
var service = serviceFactory.CreateOrganizationService(context.UserId);
I am deducing that the type of your context variable is LocalPluginContext (since this contains the UserId value) which does not expose the images (as another answer states).
To access the images, you need to get to the Plugin Execution Context:
IPluginExecutionContext pluginContext = context.PluginExecutionContext;
Entity postImage = null;
if (pluginContext.PostEntityImages != null && pluginContext.PostEntityImages.Contains("PostImage))
{
postImage = pluginContext.PostEntityImages["PostImage"];
}
In the below code segment, you are checking for the attribute "portfolio" and using "new_portfolio". Can you correct that and let us know whether that worked.
if (quote.Attributes.Contains("portfolio"))
{
var quotePortfolio = (EntityReference)quote.Attributes["new_portfolio];
contractEntity[Schema.new_contract.PortfolioName] = new EntityReference(quotePortfolio.LogicalName, quotePortfolio.Id);
}
First, you don't say what line is throwing the exception. Put in the VS debugger and find the line that is throwing the exception.
I did see that you are trying to read from a dictionary here without first checking if the dictionary contains the key, that can be the source of this exception.
var postImage = context.PostEntityImages["PostImage"];
if (postImage == null)
throw new InvalidPluginExecutionException(OperationStatus.Failed,
"Post Image is required");
Try this:
if(!context.PostEntityImages.Contains("PostImage") ||
context.PostEntityImages["PostImage"] == null)
InvalidPluginExecutionException(OperationStatus.Failed, "Post Image is required");
var postImage = context.PostEntityImages["PostImage"];
Although, I don't think that a PostEntityImage Value will ever be null, if it passes the Contains test you don't really need the null check.
I tried to follow the tutorial “Integrating Parse-Facebook in Unity” at: https://www.parse.com/tutorials/integrating-facebook-in-unity
Everything works fine but when I want to add user’s email, gender, name, birthday and location. , by using the following method :
private IEnumerator saveUserProfile(Dictionary<string, string> profile) {
var user = ParseUser.CurrentUser;
user["profile"] = profile;
user["email"] = profile["email"] ;
user["gender"] = profile["gender"] ;
user["name"] = profile["name"] ;
user["birthday"] = profile["birthday"] ;
user["location"] = profile["location"] ;
// Save if there have been any updates
if (user.IsKeyDirty("profile")) {
var saveTask = user.SaveAsync();
while (!saveTask.IsCompleted) yield return null;
UpdateProfile();
}
}
The only value added is “gender” and the other values were NOT created. Please see the below screenshot:
Also , when I presses on Facebook :” Profile No.” row in “authData” column in Parse database side , the Facebook website open with the following message :
Profile Unavailable
Sorry, this profile is not available at the moment. Please try again shortly
Please what I can do to add the above values and to get the correct profile no. for the users
Thank you
Waheed
try to check your dictionary what are the things being stored.
foreach( KeyValuePair<string, string> kvp in profile)
{
Debug.Log("Key = " + kvp.Key + " Value = " + kvp.Value);
}
I need to send an Email with a list items name of the rows my caml query picks out. I have this code:
SPQuery filter = new SPQuery();
filter.Query = string.Format("<Where><Leq><FieldRef Name=\"Revisionsdatum\" /><Value Type=\"DateTime\">{0}</Value></Leq></Where>", DateTime.Today.AddDays(14).ToString("yyyy-MM-ddThh:mm:ssZ"));
SPListItemCollection items = yourList.GetItems(filter);
foreach (var i in items)
{
string from = string.Empty;
string smtpAddress = string.Empty;
string to = "Someone#someCompany.com";
string subject = "Dudate is coming";
string body = "<h1>Hello!</h1><p>In to weeks an importent dudates comes({0}) with the name {2}.";//Here I would like to ad the dudate and the ListItems Name but how?
// get a reference to the current site collection's content database
SPWebApplication webApplication = this.Parent as SPWebApplication;
SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];
// get a reference to the "Tasks" list in the RootWeb of the first site collection in the content database
SPWeb rootWeb = contentDb.Sites[0].RootWeb;
SPList listjob = rootWeb.Lists.TryGetList("Tasks");
// Get sender address from web application settings
from = rootWeb.Site.WebApplication.OutboundMailSenderAddress;
// Get SMTP address from web application settings
smtpAddress = rootWeb.Site.WebApplication.OutboundMailServiceInstance.Server.Address;
// Send an email if the news is approved
bool emailSent = SendMail(smtpAddress, subject, body, true, from, to, null, null);
}
I would bee greatfull for your answer!
You can get it as follows:
foreach (SPListItem item in items) \\ items is your SPListItemCollection
{
var fieldValue = item["Field Name"].ToString();
}
To convert DateTime object to CAML query use SPUtility.CreateISO8601DateTimeFromSystemDateTime() method.
Fields you need are referenced by i["Title"] and i["DueDate"].
Use StringBuilder object in foreach loop to construct the body of your mail and send the email after the loop. Your code will send one mail for each task.
I have a plugin in post-operation witch need to create a folder on sharepoint via webservice, to do that, my plugin calls a webservice to execute a FechXML to get the info from the entity, but the problem is that entity still not exist, and it give me Null.
How do i force the plugin to submit/save the data to my FechXml to work?
PLUGIN CODE:
try
{
Entity entity;
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "fcg_processos")
{
throw new InvalidPluginExecutionException("Ocorreu um erro no PlugIn Create Folder.");
}
}
else
{
throw new InvalidPluginExecutionException("Ocorreu um erro no PlugIn Create Folder.");
}
processosid = (Guid)((Entity)context.InputParameters["Target"])["fcg_processosid"];
string processoid2 = processosid.ToString();
PluginSharepointProcessos.ServiceReference.PrxActivityResult result = log.CreateFolderSP("Processo", processoid2);
string resultado = result.xmlContent;
if (result.retCode > 0)
{
throw new InvalidPluginExecutionException("Ocorreu um erro na criação do Folder do Processo.");
}
WEBSERVICE CODE:
{
//WEBSERVICE TO CALL XML FROM ENTITY
PrxActivityResult Processo = ProcessoFetch2("", "", guid);
string stxml;
stxml = Processo.XmlContent;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(stxml);
XmlNodeList nodeList = xmlDoc.SelectNodes("resultset/result");
List<string[]> lista = new List<string[]>();
string[] strs = new string[7];
if (nodeList.Count != 0)//verificar o numero de registos
{
foreach (XmlNode xmlnode in nodeList)
{
if (xmlnode.SelectSingleNode("//fcg_numero") != null)
strs[2] = xmlnode.SelectSingleNode("//fcg_numero").InnerText;
else
strs[2] = "";
if (xmlnode.SelectSingleNode("//Concurso.fcg_numero") != null)
strs[3] = xmlnode.SelectSingleNode("//Concurso.fcg_numero").InnerText;
else
strs[3] = "";
}
}
IwsspClient FmwSharepoint = new IwsspClient();
PrxActivityResult folderresult = new PrxActivityResult();
List<ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave> arrayfields = new List<ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave>();
ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave nprocesso = new ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave();
nprocesso.Key = "FCG_Numero_Processo";
nprocesso.value = strs[2];
arrayfields.Add(nprocesso);
ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave npconcurso = new ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave();
npconcurso.Key = "FCG_Numero_Concurso";
npconcurso.value = strs[3];
arrayfields.Add(npconcurso);
ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave npguid = new ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave();
npguid.Key = "FCG_Guid_CRM";
npguid.value = guid;
arrayfields.Add(npguid);
folderresult = FmwSharepoint.CreateFolder("http://localhost/folder", "Processos", strs[2], arrayfields.ToArray());
res = folderresult;
}
When a plugin runs on the Post-Operation, it is still within the database transaction, and it hasn't actually been committed to the database. Any calls done with the service reference passed in as a part of the Plugin Context will be executed within the context on the database transaction and you will be able to retrieve the newly created/updated values. If you create a brand new OrganizationServiceProxy (Which I'm guessing is what you're doing), it will execute outside of the database transaction, and will not see the newly created / updated values.
As #AndyMeyers suggests in his comment (which really should be an answer IMHO), grabbing the data from the plugin context either via a pre/post image or the target is ideal since it eliminates another database call. If you're having to lookup records that may have been created by another plugin that fired earlier, you'll need to use the IOrganizationService that is included in the plugin context.
I had no option and I used this code to run webservice based on image and forget the FecthXml, as mentioned, i get all info from the Image on the post operation and send back to the WebService. Thanks, here is the code:
entity = (Entity)context.InputParameters["Target"];
concursid = (Guid)entity.Attributes["fcg_concursid"];
guid = concursid.ToString();
string npconcurs = (string)entity.Attributes["fcg_numer"];
nconcurs= npconcurs;
EntityReference nprograma = (EntityReference)entity.Attributes["fcg_unidadeorganica"];
program = nprogram.Name;
if (entity.LogicalName != "fcg_concurs")
I am working an app that read Events of a given calendar.
public static final String[] EVENT_PROJECTION = new String[] {
Events._ID, // 0
Events.UID_2445, //1
Events.DTSTART, // 2
Events.DTEND }; // 3
// The indices for the projection array above.
private static final int PROJECTION_ID_INDEX = 0;
private static final int PROJECTION_UID_INDEX = 1;
...
ContentResolver contentResolver = ctx.getContentResolver();
Uri uri = Events.CONTENT_URI;
Cursor cur = contentResolver.query(uri,
EVENT_PROJECTION, Events.CALENDAR_ID + " = ?",
new String[] { String.valueOf(calendarId) }, null);
The calendar is synched to google calendar or Exchange Server mailbox. I am able to get the event using the code above, but the I noticed that Events.UID_2445 attribute is never populated.
String uid = cur.getString(PROJECTION_UID_INDEX)); //this line always returns null
Using google calendar data api and exchange web services, I have confirmed that it has ICAL UID attribute populated. It looks like calendar sync does not store that attribute in the Event object. Does anyone else have the same issue or do you see anything wrong with the code that I use? Thanks