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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

AutoNumbering Plugin

(0) ShareShare
ReportReport
Posted on by

guys here is my code trying to make plugins for account numbering

but account number generated randomly not according to the method

code is here : 

protected override void ExecuteCrmPlugin(LocalPluginContext localContext)
{

var trace = localContext.TracingService;


if (localContext != null)
{ //The plugin context
var context = localContext.PluginExecutionContext;
var orgService = new OrganizationServiceContext(localContext.Organizati1 onService);

trace.Trace("Context", context.InputParameters);

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{

var entityFrom = (Entity)context.InputParameters["Target"];

//Get New Connection
var newconnection = orgService.
CreateQuery<new_newconnectionapplication>().
Where(a => a.new_newconnectionapplicationId == entityFrom.Id).
FirstOrDefault();

// if (!newconnection.new_customerpaid.Value)


//{ return; }
//else

//Get Accounts Under the New Connection
List<Account> listOfAccounts = orgService
.CreateQuery<Account>()
.Where(a => a.new_new_newconnectionapplication_account_NewConnectionApplication.new_newconnectionapplicationId == entityFrom.Id)
.ToList();


//var digitLength = accountNumbering.new_NumberOfDisgits;

// throw new Exception(listOfAccount.Count.ToString());
foreach (var account in listOfAccounts)
{

//Get Number configuration for account
new_numberingconfiguration accountNumbering = orgService
.CreateQuery<new_numberingconfiguration>()
.Where(a => a.new_EntityName == "account")
.FirstOrDefault();

//if (string.IsNullOrWhiteSpace(account.AccountNumber))
// {
var lastRecordNumber = accountNumbering.new_LastRecordNumber;

var accountNumber = lastRecordNumber+1;
account.AccountNumber = accountNumber.ToString();
accountNumbering.new_LastRecordNumber = accountNumber;

orgService.UpdateObject(account);
orgService.UpdateObject(accountNumbering);

orgService.SaveChanges();


//var incValue = lastRecordIncrement(lastnumber.Value);
// item.AccountNumber = incValue + lastnumber.Value.ToString();

// orgService.UpdateObject(item);
// orgService.SaveChanges();
// }
}

}


}
else
throw new Exception("Context is null");


}


// TODO: Implement your custom Plug-in business logic.


//public static int lastRecordIncrement(int record)
//{
// int constantValue = 1;
// constantValue += record;
// return constantValue;
//}

// TODO: Implement your custom Plug-in business logic.
}
}

need ur support guys pleaseee

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Guido Preite Profile Picture
    54,084 Moderator on at
    RE: AutoNumbering Plugin

    use an existing autonumber solution like this one (free and opensource)

    celedonpartners.com/.../celedon-autonumber-solution-for-dynamics-crm

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: AutoNumbering Plugin

    Hi,

    You could configure auto number generation without any code. Refer the link below.

    dynamicscrmcoe.com/auto-number-generation-dynamics-crm-2016

    Hope this helps.

  • Community Member Profile Picture
    on at
    RE: AutoNumbering Plugin

    refer arunpotti.wordpress.com/.../comment-page-1

  • Community Member Profile Picture
    on at
    RE: AutoNumbering Plugin

    Hi ,

    please follow the below steps to create a Auto number Generation

    Step 1: Download SDK Latest Version

    Step 2 : Select Sample Code Folder

    Step 3: Select CS Folder  

    Step 4 : Select Plug ins Folder (in this folder example code is given for Auto generation)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans