Search This Blog

Thursday 20 December 2012

AIF Framework in Microsoft Dynamics AX 2012 Part 1

Following the features of Application Integration Frameworl in Microsoft Dynamics AX 2012.

. Enables companies to integrate and communicate with external business processes and partners.
 
. Exchange of data through formatted XML
 
. Formatted XML is referred to as a document
 
. Service can be hosted on
 
    . AOS
 
    . IIS
 

AIF Service Types:

 
There are following three types of  Services:
 

1. Document Services:

 
Query-based services that can be used to exchange data with external systems by sending and receiving XML documents
 

2. Custom Services:

 
Can be used by developers to expose any X++ logic such as X++ classes and their members, through a service interface.
 
 Example of Custom Services is Business Operation Framework.
 

3. System Services:

 
Provided by Microsoft Dynamics AX .System services include the query service,the metadata service, and the user session service.System services are not customizable ,and they are not mapped to any query or X++ code. 
 
 In this session i will explain only Document Services.
 

Document Services:

. The XML Document Framework contains these types of classes:
 
     . Axd<Document> classes (also known as an Axd class)
 
          . containg the business logic for related entities.
 
. Ax<Table> classes
 
    . abstraction of a table and encapsulate the business logic associated with creation and modification of records in the database table.
 

AXD Document Classes:

 
These are the main methods called when data is created or updated.
1.prepareForSaveExtended.
 
  .Called when records are created.
 
2.prepareForUpdateExtended.
 
 .Called when records are updated.

Docuement Service Operations:

.create
This item creates a record for a new item in the database.
 
.delete
 
This operation deletes a record in the database.
 
.find
 
This opearation searches for the specified database record.
 
.findkeys
 
This operation retrieves a list of entity keys that correspond to the specified search criteria
 
.read
 
This operation retrieves the specified record from the database.
 
.Update
 
This operation updates the record in the databaseOnly the fields that are contained in the message are updated.Values for all other database fields remain unchanged.
 

Implementation:

Now I will show you the implementation of the Application Integration Framework.
 
Note:In this session I am showing only the example of the Document Service of AIF.
 
Step 1:
 
First of all i have created the Project in which i have create two tables and then make relations between them.In the first table I  have created the employee table which contains the fields i.e emp date of birth,emp name,emp number and than I have created the employee department table in which i have created the fields employee department and employee experience.Employee is the parent table and employee department is the child table.Than made the Query to fetch the data from these tables.Note that i have created the outer join in the query to fetch all the records and than set the property update =  true because we will also update the record in this example.
 
you can see tables of my project in the below image:
 
 
 
 
 
 



















And in the below image you can see the Query that I have created you can also see its properties.

























Step 2:

Now we will go and create our document service .

just go to the tools->application integration framework->create document service

as you can see in the below image:
















 

 A new wizard will open.Now click the next button

A new screen will come and than select your query that you have created in early step.

You can see the below image.

 
Now click the next button.A new wizard will come here you can see the axd classes names that are generated and then select operations that you want to perform through this service. and then click on the checkboxes under axbc generation.These are the proxy classes need by the Application Integration Framework.

You can see the screen in the image below:





















Now click the next button. A new wizard will open and than click the generate button.This will create the new project which contains all the proxy classes that will be use by the service consumer.As you can see in the image below:

























Now we need to register that service as valid AX service.Just right click the service file that I have highlighted in the above project and than go to adds-in and than click the register service.It will take some time to register.

Now our service is ready but not yes accessible from the outside world we need to create the inbound ports.

just go to the System Administration -> Inbound ports.

A new screen will open as you can see in the below image:
















New click on the new button as you can see in the above image to create new inbound port.
And than enter the name of the port as i have highlighted in the above image and than check the
check box include exceptions in fault.Checking this checkbox is not necessary but its for development point of view that if during the insertion of data if some exceptions occur than we can easily see that.

Now click the Service operations button as you can see in the above image.After clicking this button a new wizard will open as you can see in the below image.

 
 

Now select the service operations that we have created in the project.These service operations will be consumed by this port.

After selecting the service operations close this wizard and then click the activate button as you can see the second last image in the above.

Now your service will be activate and is able to consume by the consumer code.After the activation of the service you will get the WSDL URI that will be use in the consumer code to refrence this service. As you can see the image below the generated WSDL URI.
















Now  the process of how to consume this service I will show this in the next part 2.
I hope this session will help you on how to configure AIF service.

Thanks

Muhammad Zahid.

 
 

Thursday 6 December 2012

Unit of Work Framework In Microsoft Dynamics AX 2012

Unit of Work Framework is use to commit number of records in a single Transaction.The main reason for introducing unit of work is that it is impossible to insert the lines table record before its header table  because there is a relation between the header table and the lines table.The Recid of the header table is comes as a foreign key in the child table.

Lets took an example as you can see in the microsoft dynamics ax there are two tables i.e custtransopen and custtransopenline.These two tables are related with each other CustTrabsOpen is the parent table and custtransopenline is the child table.

As you can see in the below image about  these two tables and there relations.


There is a common field on both the tables i.e amountcur.

In the parent table i.e in the custtransopen table this amountcur contains the total of the custtransopenlines amountcur.
Now we cant insert the records in the custtransopenline table because it needs the recid of the parent table i.e custtransopen and similarly we cant insert thet record first in the parent table i.e custtransopen because it needs the total amountcur from the custtransopenline.

To resolve this issue Unit of Work Franework is introduced.It allows to perform create, update and delete operations without worrying about the order of those and without a need to specify surrogate key values. It will all be done automatically in the kernel!

Now to show the Implementation of the Unit Of Work I have created two tables i.e invoiceheader and invoiceline and than made the relation between them.The invoiceheader contains the field i.e totalquantity which holds the total quantity of the invoiceline field i,e quantity.

Below image will show you these two tables,their fields and there relations.
























Now the below  job will insert the invoiceheader with calculated totals and 2 lines. Note, that there is no place where recid is mentioned in the code. Business data only.







































One thing that I need to mention there is that.In the above code I have write the code i.e "line.invoiceheader(header);"

This is the method use to link the invoiceline table and the parent table.To call this method we have to first set the property CreateNavigationPaneProperty to "Yes".As shown in the image below:



Now When I run this job an exception will occured as you can see in the below image.

























I have run a job due to this issue the exception is occured to resolve this issue I have to make a static method inside the class and also include server tags in that method.as you can see in the below image.







Now when I call this method the data will be inserted successfully.you can see the below image of tables which contains the data that I have inserted.
 



 

 
 




































Thanks

Muhammad Zahid.

Saturday 1 December 2012

Links on Fields on Forms

When we open the form.There are some fields which are like hyperlinks and when we click on these
fields a new form is open.

As you can see the example below just go to the Account Receivable->Customers->All Customers.
The new form will open with fields cotaining the hyperlink.





And when I click on this field a new form is open as you can see in the below image.

 
 
 
Basically these fields physically exist in other table and they are showing on this table through foreign key.
 
The question is how the form is open when we click on these fields.The simple answer is that to open the form on this field just go to the table in which this field actually resides and than in the property of that table set the formref=formname.

Now The Query that shows the data on the Preview Pane is "CustListPagePreviewPane".In that Query there is table i.e custtable which uses that field i.e "CustGroup".Now we will go into the relation of that table to show that what is the parent table in which this field actually exist.

You can see the image of the custtable in the below image.























Now we will go to the property of the table CustGroup and see the FormRef propery.

















As you can see the name of the form in the formref property.This is the form which open when we click on the link custgroup.

Thanks

Muhammad Zahid.
 

Tuesday 20 November 2012

Preview Pane In Dynamics AX 2012

A preview pane is the part of a list page that shows additional information about the highlighted record in the list. A preview pane is optional and is located under the list page grid.

Note:Preview Pane is just like FactBox of  type InfoPart.For making Preview Pane we just need to set the property of this part inside the part node of the form of part location to PreviewPane.

Below in the image is the Preview Pane in a list page.














Steps for Creation of Preview Pane is very simple we have to first made a info
part as we made it for FactBox.

Here is the link below on how to make the InfoPart.

http://codingchamp.blogspot.com/2012/11/fact-box-in-microsoft-dynamics-ax-2012.html

Than we have to make a Display Type Menu Item.In which we set object type to InfoPart and object to name of the infopart.

Than We go to part node of the Form and than right click and than select new refrence name and than specfied the name of the menu item and than setting part location to PreviewPane.

If you want to explore more for the preview pane than here is the link below.

Preview Pane

Thanks

Muhammad Zahid.
 

Friday 16 November 2012

Fact Box in Microsoft Dynamics AX 2012

Fact Box is basically use to show the data related to the selected record.

The FactBox pane is the area of a form where a part that you add to a form appears as FactBox. A part is a specialized type of control that can retrieve and show additional information. When you view the form, the part appears as a collection of read-only data called a FactBox. For information about parts.

To have a FactBox appear in a form, the form must include a FactBox pane. The following types of forms include a FactBox pane:
  • List pages
  • Details forms
The FactBox pane is optional and if the form does not have any parts, the FactBox pane does not appear. A FactBox pane can show more than one FactBox.
The parts you add to the FactBox pane create FactBoxes that show additional information about the record that appears in the form. The FactBoxes enable you to view related information without having to find and open a separate form. In addition, you can configure the part so that the contents of the FactBox update when you move to a new record.
 
For Fact Boxes we basically uses the Parts.There are three types of parts in Microsoft Dynamics AX these are:
 
1.Info Part.
 
2.Form Part.
 
3.Cues.
 
1. Info Part:
 
An info part is a type of part that you use to add a collection of fields and values to the FactBox pane of a form, or the preview pane of a list page
 
In Info Part we just specified the Query and in the layout node of the info part we just add fields and in the properties of these fields and than specified the datasource name and the field name.
 
Below is the image of the Info Part on the Form.

















Below is the info part in the AOT.

























For Showing the info part on the forms we just made infopart inside the Parts->InfoPart node of the AOT and than create a menuItem with object type=InfoPart and object =name of the infopart and than we go to the parts node of the form and than right click and than select new refrence name and than new part refrence and than specfied the name of the menu item and than setting part location to Auto.

Below is the parts node of the Form HcmWorkerListPage and the properties of the selected part.





 note:Info Part can be shown on both the cleint and Enterprise Portal. For Implementation of Info Part you can see my other post.
Just click on the below link

Info Part In Microsoft Dynamics AX 2012.

2. Form Part:

A form part is a pointer to an existing form. You use a form part to make the form appear in the FactBox pane of a form, the preview pane of a list page, or the enhanced preview of a control.
Take care to select a form that fits the location where the form part appears. For example, a form with a large grid and several controls might not fit the space available for a FactBox or enhanced preview. Typically, you select a form that was designed for use in the FactBox pane, preview pane, or enhanced preview

Below is the image of the FactBox of type FormPart.










We use Form Part to show the form in fact box.Form part is very simple we just specified the name of the Form in the property of the FormPart.

Below is the image of the Form Part its properties in the AOT .


For Showing the formpart on the forms we just made formpart inside the Parts->FormPart node of the AOT and than create a menuItem with object type=FormPart and object =name of the formpart and than we go to the parts node of the form and than right click and than select new refrence name and than new part refrence and than specfied the name of the menu item and than setting part location to Auto.

3. Cues and Cues Group:

Cues are basically use to show the number of records against the selected record and sum of the particular field.However calculation for the sum is optional.

For example we go to the list page which contains all the customers than we select the customers than in the fact box their will be the cue which shows the number of sales orders against that customer and the sum of particular field  that we have presented in the Fact Box.

Note:Cues can not be shown alone on the fact box.We first have to make the Cues and make a Cues group and than drag and drop our Cues into the Cues Group.

Below is the image which shows the Cues how they looks like.






 
 
As you can see in the image that the cues are in hyper link this because when we click on that link a new form will open with the related information like customer sales orders,cutomer open invoices etc.

Below are the steps for creating the Cues and CuesGroup

1.For Creating Cues we have to first create the menu item and in the property sheet of the menu item we have to set the name of the form and the Query which retrieves the record against the select record.

2.Than we have to go to the parts->Cues node in the AOT and create new Cue and in the property sheet of the Cue we set the name of the menuitem that we have just created.and if we want to show the sum of particular field than we will set the property calculate sum =yes and table=table name and field =field name as you can see in the below image.

note:Specifies whether to show a sum for the cue. The default value is No. To calculate a sum, the field must be one of the following Extended Data Types:
  • AmountCur
  • AmountMST
In addition, the table in the data source must have a field of type CurrencyCode.
 



3.Than we go to the Cue Group node and than create new Cue Group and  than drag and drop the Cues to the to the newly created Cue Group.

Below is the image of the Cue Group and its properties.



4.Than we have to make a menuitem and than setting its object type to CuesGroup and   object to  name of the Cue Group.

5.Than we go to the parts node of the form and than right click and than select new refrence name and than new part refrence and than specfied the name of the menu item and than setting part location to Auto.
 
 
 Below are the some links for Deep Drive in Fact Boxes:

Fact Box

InfoPart

FormPart

Cues and Cue Group


Thanks,

Muhammad Zahid.


 

Thursday 1 November 2012

Field Group In Dynamics AX 2012

Field Group is basically use for logical grouping of data for example we require employee personal information on different forms than we just put fields related to employee personal information into the  field group and than put that group field on to the form.Than Automatically show the fields of Employe Personal info on the form.

The benefit of the field group is that when we want to add or delete value from the field group it automatically reflects on the form which using that field group.

The side effects of the field group is that we can not modify the single form which uses the field group.Than we have to remove field group from that form and put individual fields.

For more exploration on field group here is the link below:

http://msdn.microsoft.com/en-us/library/bb314861.aspx

 

Wednesday 31 October 2012

Coding Best Practices In Dynamics AX 2012

There are some coding best practice strategies that every one should follow to avoid Best Practice Errors.

1. Use camel cases for all the member variables i.e serverClass (First alphabet of the work should be small and second alphabet should be capital).

2. Use Pascal Case Naming  Convention for application Object Tree Elements.

e.g:AddressCountryRegion

First letter of each word should be capital.

3. Parameters Names in Methods should start with _ (underscore).

4. Do not encode the type of a variable in its name eg strName (This is wrong).

5. Do not use multiple comments use only single line comments.No matter how many lines the comment contains.

6. Do not use comment at the end of the line.Unless the comment is very small
e.g: int count; //-1 indicates.

7. Remove Todo comments in advance of a release.

( Todo Comments are basically the comments of code that this code contains bug we will fix it latter or etc.)

8. XML Documentation is  basically the Description  of the method and  its parameters.

We must place XML Documentation above every method.

To create the XML tags place /// above the method or right click
scripts->documentation->HeaderTemplate.

9. Put the method calls inside the conditions so if call are fails than method calls cost will reduce.This is benefit of taking less time consuming.

10. Use field list in select statement.

11. Use Extended Data Types whereever possible.

12. For constant values that are use in multiple places in code you should use #define to define macro that has the constant value.

Example for defining Macros.

#define. MacroName('value')

Example for using Macros.

variable=#Macroname.

13. Use local variables as more as possible.

14. Avoid Global variables as more as possible.

If  you want to explore more in Coding Best Practices than here is the link below:

http://msdn.microsoft.com/en-us/library/gg865121.aspx

Thanks

Muhammad Zahid.
 

Friday 19 October 2012

Unit Test Framework In Microsoft Dynamics AX 2012

The Unit Test framework is tightly integrated into the MorphX IDE of Microsoft Dynamics AX. This integration is very important to test-driven development (TDD) because a unit test can be created alongside the feature code it is testing.

What is a Unit Test:

A unit test is code that verifies that feature code has been implemented correctly. If you adhere to the principles of TDD, it is best for the developer who is writing the feature code to first write the unit tests. This puts emphasis on how feature code is consumed and creates a more user friendly application programming interface (API). A unit test, in the context of the Unit Test framework, includes test cases, how test cases are staged with data, and the organization of test cases. A test case is a class that extends the SysTestCase Class class. You can add test methods to test each requirement of the feature code. You should execute test cases when code is changed.

Some Important Points:

Every test case class should extend  SysTestCase Class.

For testing purpose you can write multiple methods for single actual method in code.

For Classes their should only one class for testing a single class.

Name the test class same as the class followed by test in the end.

Name of the method in the test class should also contains test  in the start.

We write Unit Test for classes and tables only.

Always Testing will be done on Blank Database.

The attribute that must be placed on the unit test case class is:

[SysTestTargetAttribute('SysDictTable',UtilElementType::Class)]

The attribute that must be  placed above the method of the test case is:

[SysTestMethodAttribute]

Methods for Setting Data:

Two types of methods are use for setting up data.These are:

1. Setup Method.

2 Setup Test Case Method.

1.Setup Method:

Setup Method runs before every Test method.For some times we usaually want fresh data so we write code in setup method.It works like this:First setup method executed than test method executed than tear down method executed than again setup method executed with fresh data than second test method executed and so on.

2.Setup Test Case Method:

Setup Test case method runs only one time when test class is executed.In case of setup test case method it executed only one time and than tear down method for setup test case method will execute in the end.

note:Due to some issues we usually dont use i.e override setup test case method we only use setup method.

Tear Down Method:

Tear Down method is basically use to flush out data.We normally dont override this method.It manages Automatically.

A test method will typically contain several assertions that are required to hold true,for the test to be successful.

Note: The use of the assertEquals method.This method,and other assert methods,are available as part of the SysTestCase framework.These methods also have an optional string parameter called _message,to specify the message that would go into the infolog.If the assertion fails.The following is list of available methods:



























Now I will show u the simple example on how to use the Unit Testing.

Create a simple class that contains add,subtract and multiply methods.

Now Create the Unit Test to Test this classes.The original class on which I have made these methods is Calculations.Now for unit test first we will override the setup method.



public class calculationtest extends systestcase
{
calculation obj;
}

pulbic void setup()
{

 obj=new calculation();

super();

}

public void testadd()
{
this.assertequal(3,obj.parmadd(1,2));
}
public void testmultiply()
{
this.assrtequal(9,obj.multiply(3,3));
}

Class Declaration:

[SysTestTargetAttribute('calculation',UtilElementType::Class]
public class calculationtest extends SysTestCase
{
calculation obj;
}

Methods:

[SysTestMethodAttribute]
public void testadd()
{
this.asserEquals()3,obj.add(1,2);
}

[SysTestMethodAttribute]
public void testsubtract()
{
this.assertEquals(1,obj.subtract(1,2));
}

[SysTestMethodAttribute]
public void testmultiply()
{
this.assertEquals(9,obj.multiply(3,3));
}

Running Test Cases:

Now right click the test class i,e is calculationtest and than go to add ins than click the run test tests as
you can see in the below image:

 
 
Now after running the unit tests you can see in the above image that the how much methods are runs how much are fail as you can see in the image.
 
 

 

You can also record the code coverage of the code just click on the parameters button as you can see in the above image.

A new screen will open.Now check the checkbox record code coverage and record number of records.as you can see in the below image.






















Now click on the Listener as you can see in the above image and select infolog.This is for when some exception occur than it will be show in the infolog.

Below is the screen for the infolog.

Now close the above form and than again run the unit test and than click the details button as you can see in the 3rd last image and a new form will open and where you can see the code coverage.

The recomended code coverage of the class should be 60%.

You can see the code coverage of my class in the below image:














You can also see the code coverage of the methods also.Just select your recently run testcase and than click the test button as you can see in the above image.

A new form will open which shows the code coverage of the methods as you can see in the below image.

 
Thanks
 
Muhammad Zahid.






Saturday 13 October 2012

Queries In Dynamics AX 2012

Types Of Queries :

There are three types of queries in dynamics ax 2012:
1. Inline Queries.
2. Aot Queries.
3. Queries objects and API.
1. Inline Queries:
Inline queries are similar to the Linq queries in dot.
In inline queries you need to create the table buffer.
Table Buffer is quite similar to the objects in classes.
In Dynamics Ax tables can also be treat as a classes where you can write your own methods.
Below is the simple example of inline queries.
CustTable custTable;
 select AccountNum from custTable order by AccountNum where custTable.AccountNum>="1000";
info(custTable.AccountNum);
I you want to show all the records in the info box than we use while statement
while   select AccountNum from custTable order by AccountNum where custTable.AccountNum>="1000";
{  
 info(custTable.AccountNum);
 }
We can also use aggregate functions  in  inline queries.
Here is the example given below:

 select count(AccountNum) from custTable where custTable.AccountNum>"1000";

info(custTable.AccountNum);

Joins in Inline Queries:
Lets make it little bit more interesting by using joins:
HcmBenefit hcmBenefit;
HcmBenefitPlan hcmBenefitPlan;
while select * from HcmBenefit join HcmBenefitPlan
where hcmBenefit.BenefitPlan==hcmBenefitPlan.RecId
{
info("%1,%2",hcmBenefit.BenefitPlan,hcmBenefitPlan.RecId);
}


Group By Clause in Inline Queries:


Group by clause is basically use when we use aggregate functions.Lets see an example:

while select count(RecId) from hcmBenefit
join Description from hcmBenefitPlan
 group by hcmBenefit.BenefitPlan,hcmBenefitPlan.Description
where hcmBenefit.BenefitPlan==hcmBenefitPlan.RecId
{
info(strfmt("%1,%2",hcmBenefit.RecId,hcmBenefitPlan.Description));
}


Inline Queries -Select Options :






If you want to explore more than you can refer to the following link:
 
 
Simple Insert,Update,Delete:
Insert:
Student  student;
student.name="muhammad zahid";
student.insert();
Update:
select forupdate from student where student.name=="muhammad zahid"
if(student.RecId>0)
{
ttsbegin;
student.name="Baber Tareen";
student.update();
ttscommit;
}
note:The if check was only to check that if the record exist or not that i have fetch.You can remove this if check if you want.
Delete:
select forupdate from student where  student.name="Baber Tareen";
if(student.RecId>0)
{
ttsbegin;
student.delete();
ttscommit;
}
Insert And Update multiple records at a Time:
For inserting multiple data at a single time we use insert_recordset and for updating multiple data at a single time we use update_recordset 
update record set
insert_recordset:
insert_recordset myTable(myNum,mySum)
select myNum,sum(myValue) from anotherTable
group by myNum where myNum <= 100
note:here mytable is the table in which we are inserting the bulk record and the fileds are those in which we inserting data and than the select query which fetch the record whic we are inserting in our table.    
update_recordset:
update_recordset student setting
name="zahid";
the above code will update all the names fields to zahid.You can also use where clause to update the selected record set.
The pseudo code for the update record set is:
update_recordset my TableBuffer setting
field1=1,
field2=fieldX + filedY
where field1==0

 

AOT Queries:

AOT Queries are those queries that we made in AOT by the help of the wizard.

below is the image of the AOT Queries.







Calling Aot Queries:
 
HcmBenefit hcmBenefit;
 
HcmBenefitPlan hcmBenefitPlan;
 
Query q=new Query(queryStr(BenefitQuery));
 
QueryRun qr=new QueryRun(q);
 
while(qr.next())
{
hcmbenefit=qr.get(tableNum(hcmBenefit));
 
hcmBenefitPlan=qr.get(tableNum(hcmBenefitPlan));
 
info(strfmt("%1,%2",hcmBenefitPlan.Description,hcmBenefit.RecId));
}
 

Query Build API:

Query:
 
Contains the definition of the query.Can consist of one data source or several data sources if they are related.
 
Query Run:
Class use to execute the query and loop through reuslt.
 

Query Build DataSource:

Links to one datasources in query.
 
Query Build Range:
 
Enables the end user to limit the result by adding a value in the specified query range.
 
QueryBuildFieldList:
 
List of all the fields in data source.
 
Query Build Link:
 
Links two data sources in a join.Is set on the child data source.
 
Using Aggregates and Sorting:
 
 
 
 
 
Using Joins:
 



 

some usefull links so you can deeply explore.
 
 
 
 
Thanks
 
Muhammad Zahid. 
 
 
 

Thursday 11 October 2012

Map and MapEnumerator Class

Map Class:


                       The Map class lets you associate one value, that is, the key, with another value. Both the key and value can be any valid X++ type. This includes objects. The types of the key and the value are specified in the declaration of the map. The way in which maps are implemented means that access to the values is very fast.

we can also assign our hard coded key value and value in maps.

I will show you the little example on how to implement Maps.This will make more clear concepts.

Map zahidmap;
 
zahidmap=new Map(Types::Integer,Types::string);
 
zahidmap.insert(1,"Muhammad Zahid");
 
zahidmap.insert(2,"Asim Saeed");
 
zahidmap.insert(3,"Baber Tareen");
 
if(zahidmap.exist(1))
{
info(strfmt("%1",zahidmap.lookup(1)));
}
 
if(zahidmap.exist(2))
{
info(strfmt("%1",zahidmap.lookup(2)));
}
 
if(zahidmap.exist(3))
{
info(strfmt("%1",zahidmap.lookup(3)));
}

In the above code I have just created the map with key value type=integer and value type =string
than I have inserted the key value and value into the map and than i have just made an if  check whcich checks that if this key is exist or not and by m.lookup method i just return the value against the key that I have passed into the parameter.

Output:

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

 

MapEnumerator:

 
The MapEnumerator class allows you to traverse through the elements within a map.
 
Example:
 
This example is proceeding from the above created example.
 
As I have already created the map.Now in this example i will assign this map to the map enumerator.

MapEnumerator zahidmapenumerator;

zahidmapenumerator=zahidmap.getEnumerator();

while(zahidmapenumerator.movenext())
{
info(strfmt("%1",zahidmapenumerator.currentvalue()));
}

The outpur will be the same as you can see in the above image.

Thanks

Muhammad Zahid.
 
   

Wednesday 10 October 2012

Assigning roles in Sql Server 2008 R2

Go to security => login tab of the security tab of  Sql server 2008 R2 right click and than select new login as u can see in the below image:


























Now click on the new login and than enter the login name as u can see in the image below:























Now click on the server roles and check the roles you want to assign to that user as you can see in the image below:
























Now click on the user mapping than check the database on which u have to assign the role related to that database and than select the checkboxes below which shows the roles related to selected database as you can see in the image below.























Now check the another database and than repeat the steps as I have stated above.

Thanks

Muhammad Zahid.



Error 3154:The backup set holds a backup of a database other than the existing 'AXDBDEV' database


This error message  will produce when we restore our database from the database backup file:

There are following easy steps to resolve this issue:

Step 1: 

First right click the existing database which you want to restore than go to:
 
task => restore => database
 
as you can see in the below image:
 
 





 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Step 2:

A new wizard will open.Now click on the options then check the checkbox
 
"Overwrite the existing database (with replace)" 
 
as you can see in the below image.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Now perform the rest of the steps for restoring the database.The error message will not be produce again.
 
 
Thanks
 
Muhammad Zahid.