Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

please tell me what mistake i did in it

(0) ShareShare
ReportReport
Posted on by 76


if (context.InputParameters != null)
{

QueryExpression query = new QueryExpression("divine_autonum");
query.ColumnSet = new ColumnSet();

int totalrecords = 0;

EntityCollection ec = service.RetrieveMultiple(query);
totalrecords = ec.Entities.Count;

if (totalrecords == 0)
{
Entity num = new Entity("divine_autonum");
num["divine_name"] = "dota";
num["divine_pre"] = "A";
num["divine_number"] = "1";
num["divine_sepa"] = "*";
num["divine_sufix"] = "B";
tracingService.Trace("Auto numbering on account entity: Creating the trecords");
service.Create(num);
}
}

Second program

QueryExpression query1 = new QueryExpression("account");
query1.ColumnSet = new ColumnSet();

EntityCollection ec1 = service.RetrieveMultiple(query1);

int totalrecord = ec1.Entities.Count;

if (totalrecord > 0)
{

Entity num1 = new Entity("divine_autonum");

num1["divine_number"] = Convert.ToString(totalrecord + 1);

ColumnSet attributes = new ColumnSet(new string[] { "num_pre", "num_number", "num_sepa", "num_sufix" });

Guid num1Id = default(Guid);
num1 = service.Retrieve(num1.LogicalName, num1Id, attributes);

service.Update(num1);

}

}
}
}

Can i write both in same plugin i  need to update "divine_number" field using plugin 

how can i do it please explain 

*This post is locked for comments

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: please tell me what mistake i did in it

    Hi Hemanth,

    I would suggest you to register your plugin on pre operation and pass context entity as parameter to create auto-number as shown below:

    Entity num = new Entity("divine_autonum");

    num["divine_name"] = "dota";

    num["divine_pre"] = "A";

    num["divine_number"] = "1";

    num["divine_sepa"] = "*";

    num["divine_sufix"] = "B";

    context.InputParameters["Target"] = num;

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: please tell me what mistake i did in it

    Hi Hemanth,

    I would suggest you to register your plugin on pre operation and pass context entity as parameter to create auto-number as shown below:

    Entity num = new Entity("divine_autonum");

    num["divine_name"] = "dota";

    num["divine_pre"] = "A";

    num["divine_number"] = "1";

    num["divine_sepa"] = "*";

    num["divine_sufix"] = "B";

    context.InputParameters["Target"] = num;

  • Suggested answer
    Dharanidharan Profile Picture
    636 User Group Leader on at
    RE: please tell me what mistake i did in it

    From your code I understood that you are trying to implement the auto number feature while creating the account records.

    If so below logic you can use in plugin and achieve this.

    Reference link : passion4dynamics.com/.../how-to-create-auto-number-field-in-crm

  • Radu Chiribelea Profile Picture
    6,667 on at
    RE: please tell me what mistake i did in it

    Could you please explain what you are trying to achieve ? Not just pasting the code, however please provide an end to end overview on what you are trying to do.

    Also, when you say that the update is not working - do you get an error message or what exactly happens?

    The more accurate the information is, the easier is for the community members to understand your challenge and provide relevant input.

  • Radu Chiribelea Profile Picture
    6,667 on at
    RE: please tell me what mistake i did in it

    Could you please explain what you are trying to achieve ? Not just pasting the cove, however please provide an end to end overview on what you are trying to do.

    Also, when you say that the update is not working - do you get an error message or what exactly happens?

    The more accurate the information is, the easier is for the community members to understand your challenge and provide relevant input.

  • Hemanth Reddy.B Profile Picture
    76 on at
    RE: please tell me what mistake i did in it

    First program is working but update is not working

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans