web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM Dynamics 2013 How to get the current user view url in c# code

(0) ShareShare
ReportReport
Posted on by 70

I have a scenario in CRM where I have a MVC application that connect to CRM and user uploads an excel file with data, that data gets validated against a proc the validated results(records) are then created in CRM using the MVC Application. After the records are created I then send an email to the logged in user's manager ,this email needs to contain a URL/Link to the view where the records have just been created, which is My Active Supplier Claims Update in my instance, How do I query CRM to get the View URL for that logged in user just before I send the email. Please see my code below as to how far I got, I am a bit stuck with this step.

public ActionResult ImportDataToCRM(CRM_Embrace_IntegrationEntities1 db)
    {

        int sessionIdentifier = (int)Session["sessionID"];

        var claimsRecords = db.GPClaimsReadyToImports.Where(x => x.CleanSupplierClaimSessionID == sessionIdentifier).ToList();

        CrmConnection conn = new CrmConnection("CRM");
        var service = new OrganizationService(conn);
        OrganizationServiceProxy proxy;// = new OrganizationServiceProxy;
        WhoAmIRequest whoReq = new WhoAmIRequest();
        WhoAmIResponse whoResp = (WhoAmIResponse)service.Execute(whoReq);
        Guid userid = whoResp.UserId;

        proxy = service.InnerService as OrganizationServiceProxy;
        proxy.CallerId = whoResp.UserId;

        conn.CallerId = userid;

        var cleanClaimsFromDB = claimsRecords; 

        foreach (var claim in cleanClaimsFromDB)
        {
            new_supplierclaimsupdate CRMSupplierClaimsData = new new_supplierclaimsupdate()
            {
                new_Action = claim.Action.Trim(),
                new_InvoiceNumebr = claim.Line_Number.Trim(),
                new_Warning = claim.Warning.Trim(),
                new_TotalClaim = Convert.ToDecimal(claim.Total_Claim).ToString(),
                new_Currency = claim.Currency.Trim(),
                new_Supplier = claim.Claim_Reference.Trim(),
                OwnerId = new EntityReference(SystemUser.EntityLogicalName, userid),
            };

            Guid _supplierClaimID = service.Create(CRMSupplierClaimsData);

            TempData["supplierClaimID"] = _supplierClaimID;

        }

        Guid supplierClaimsRecordId = Guid.Parse(TempData["supplierClaimID"].ToString());

        Email email = new Email();

        ActivityParty from = new ActivityParty();
        email.OwnerId = from.PartyId = new EntityReference("systemuser", Guid.Parse("B8CB8298-43F4-E211-A707-D067E5EBE694"));

        ActivityParty to = new ActivityParty();
        to.PartyId = new EntityReference("systemuser", Guid.Parse("C4354817-147E-E511-80D4-00155D060AC7")); 


        email.From = new ActivityParty[] { from };
        email.DirectionCode = true;
        email.To = new ActivityParty[] { to };
        email.Subcategory = "Manager To Review Claims Updated  By User";
        email.Description = //The URL VIEW WILL BE ADDED HERE.
        email.RegardingObjectId = new EntityReference("new_supplierclaimsupdate", supplierClaimsRecordId);
        service.Create(email);



        return View("ImportReadyClaims", cleanClaimsFromDB);
    }


How can I do this in C# Code. I know of an OOTB way in CRM but that is using an On-Demand workflow and that is not part of the requirement, as this needs to be automated. I would really appreciate your help.

I have a scenario in CRM where I have a MVC application that connect to CRM and user uploads an excel file with data, that data gets validated against a proc the validated results(records) are then created in CRM using the MVC Application. After the records are created I then send an email to the logged in user's manager ,this email needs to contain a URL/Link to the view where the records have just been created, which is My Active Supplier Claims Update in my instance, How do I query CRM to get the View URL for that logged in user just before I send the email. Please see my code below as to how far I got, I am a bit stuck with this step.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Haansi Profile Picture
    1,433 Moderator on at

    Hi Papi,

    Are you trying to put a CRM link in an email which user will click and see the record ?

    You can do that but you can't skip CRM security. All entity forms and views are displayed in CRM main.aspx page. Url string will depend on CRM environment. Please see this article for details.

    msdn.microsoft.com/.../gg328483.aspx

    If you were trying to get Url of MVC view please consult this page:

    stackoverflow.com/.../how-to-get-the-url-of-the-current-page-in-c-sharp

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans