WebJobs Without Client Id and Client Secret

Create a web job and get all active contract records which will be expire in 7 days.

So for the above scenario we have to create a Contract. 

  1. For Contract creation you should go for advance in advance settings.
  2. Now search contracts and click on result > click on new contract to create a contract.
  3. Then a select template popup will be displayed > now in check box click on search icon and select service 
  4. While creating contract we should provide some mandatory details. They are
  5. contract name , customer , contract start date  , contract end date  and bill to customer 
  6. Now according to our scenario the contract start date and contract end date difference should come for 7 days and that should be visible in Duration in days where as 7 days 
  7. After Creating of contract you should create contract line which is visible left side of the contract which was created. 
  8. In contract lines we have some mandatory fields they are
  9. Title ,Total cases / minutes and total price. After giving these details click on save 
  10. To activate contract on top we have blue ribbon bar click on service and click on contracts there your new contract which is created will be visible. Beside it we have a check box click on it and on top Click on active then your contract will be activated. 
  11. Now again click on advance find search according to the below filter image > click on result > click download fetch Xml.

The Fetch XML Code is : 

"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +

"  <entity name='contract'>" +

"    <attribute name='title' />" +

"    <attribute name='contractid' />" +

"    <order attribute='title' descending='false' />" +

"    <filter type='and'>" +

"      <condition attribute='statecode' operator='eq' value='2' />" +

"      <condition attribute='billingendon' operator='next-seven-days' />" +

"    </filter>" +

"  </entity>" +

"</fetch>";

12. Now go for console application in visual studio and write the code.

Code for Web Jobs Without Client Id and Client Secret Id 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Microsoft.PowerPlatform.Dataverse.Client;

using Microsoft.Crm.Sdk.Messages;

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Tooling.Connector;

using Microsoft.Xrm.Sdk.Query;

using Microsoft.Rest;


namespace wEbJoBcheckQ

{

    class wEbJoBcheckQ

    {


        static string url = "https://org***bc6ea.crm8.dynamics.com/main.aspx?";

        static string UserName = "hanu.harish@****.com";

        static string PassWord = "****@202020";

        static string connectionString = $@"

        AuthType = OAuth;

        Url ={url};

        username ={UserName};

        password = {PassWord};

        LoginPrompt=Auto;

        RequireNewInstance = True";

        static void Main(string[] args)

        {

            //ServiceClient implements IOrganizationService interface

            IOrganizationService service = new ServiceClient(connectionString);

            var response = (WhoAmIResponse)service.Execute(new WhoAmIRequest());


            //CrmServiceClient service = new CrmServiceClient(connectionString);

            string contractFetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +

"  <entity name='contract'>" +

"    <attribute name='title' />" +

"    <attribute name='contractid' />" +

"    <order attribute='title' descending='false' />" +

"    <filter type='and'>" +

"      <condition attribute='statecode' operator='eq' value='2' />" +

"      <condition attribute='billingendon' operator='next-seven-days' />" +

"    </filter>" +

"  </entity>" +

"</fetch>";


            EntityCollection contractActive = service.RetrieveMultiple(new FetchExpression(contractFetchXml));


            foreach (Entity contrcatActive in contractActive.Entities)

            {

                string contrcatName = contrcatActive.Contains("title") ? (string)contrcatActive.Attributes["title"] : null;

                Console.WriteLine(contrcatName);

            }

            Console.ReadLine();

            Console.WriteLine("contrcatName");

        }  

    }

}


Comments

Popular posts from this blog

If any case created, then check for the same user how many cases are created with in 30 days, if more than 2 and less than 5 send a mail to team lead, if more than 5 and less than 9 then send a mail to manager using power automate.

Create approve & reject ribbon buttons, once click on approve it should change the status field to approve.If clicked on reject it should change to Reject. Based on status field change trigger work flow to send a email to stating request is approved/Rejected.

How to get and set values in plugins?