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)

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

I have the same question (0)
  • Hemanth Reddy.B Profile Picture
    76 on at

    First program is working but update is not working

  • Radu Chiribelea Profile Picture
    6,667 on at

    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.

  • Radu Chiribelea Profile Picture
    6,667 on at

    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.

  • Suggested answer
    Dharanidharan Profile Picture
    638 User Group Leader on at

    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

  • Suggested answer
    Pawar Pravin Profile Picture
    5,237 on at

    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

    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;

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