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.
- For Contract creation you should go for advance in advance settings.
- Now search contracts and click on result > click on new contract to create a contract.
- Then a select template popup will be displayed > now in check box click on search icon and select service
- While creating contract we should provide some mandatory details. They are
- contract name , customer , contract start date , contract end date and bill to customer
- 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
- After Creating of contract you should create contract line which is visible left side of the contract which was created.
- In contract lines we have some mandatory fields they are
- Title ,Total cases / minutes and total price. After giving these details click on save
- 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.
- 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
Post a Comment