@selvam214 – when looking at your screenshot you are selecting objects that cannot be part of one group.
You cannot group anchored pageItems, nested graphics and "regular" pageItems to one group. And allPageItems will give you too much objects.
Another thing would be: You should add the group to a specific page.
Not just add the group to the document.
And you will have issues with locked page items…
//Locked pageItems could prevent items from beeing grouped.
//So we have to unlock all pageItems:
app.activeDocument.pageItems.everyItem().locked = false;
var myPages = app.activeDocument.pages;
for(i=0; i<myPages.length; i++){
//If there are no pageItems on a page, you cannot add a group.
//If there is only one pageItem on a page, you cannot add a group.
if(myPages.pageItems.everyItem().getElements().length > 1){
myPages.groups.add(myPages.pageItems.everyItem().getElements());
};
};
Uwe