แชร์ผ่าน


pac power-fx

(ตัวอย่าง) คําสั่งสําหรับการทํางานกับ Power Fx

ใช้คําสั่งเหล่านี้เพื่อโต้ตอบกับข้อมูลใน Dataverse โดยใช้บรรทัดคําสั่งหรือสคริปต์ ลดเวลาและความซับซ้อนของการดําเนินการ Dataverse ของคุณโดยใช้ Power Fx

คุณสามารถใช้สูตรที่แสดงอยู่ใน การอ้างอิงสูตร - Power Platform CLI ได้

คำสั่ง

คำสั่ง คำอธิบาย
pac power-fx repl (ตัวอย่าง) เปิดใช้การวนรอบการอ่าน-Eval-Print ของ Power Fx แบบโต้ตอบ
เรียกใช้ pac power-fx (ตัวอย่าง) เรียกใช้ไฟล์ของคําแนะนํา Power Fx

pac power-fx repl

(ตัวอย่าง) เปิดใช้การวนรอบการอ่าน-Eval-Print ของ Power Fx แบบโต้ตอบ

Note

หากคุณ ติดตั้ง Power Platform CLI โดยใช้ Windows MSIจะมีปัญหาที่ทราบซึ่ง pac power-fx repl เชลล์อาจหยุดการตอบสนองเมื่อใช้คําสั่งนี้

พารามิเตอร์ตัวเลือกสําหรับ power-fx repl

--environment -env

ระบุ Dataverse เป้าหมาย ค่าอาจเป็น Guid หรือ https URL แบบสัมบูรณ์ เมื่อไม่ได้ระบุ องค์กรที่ใช้งานอยู่ที่เลือกสําหรับโพรไฟล์การรับรองความถูกต้องปัจจุบันจะถูกใช้

หมายเหตุ

คําสั่งนี้ให้เชลล์เพื่อใช้สูตรที่แสดงอยู่ใน การอ้างอิงสูตร - Power Platform CLI

เริ่มการตอบกลับ Power Fx โดยการเรียกใช้คําสั่งต่อไปนี้:

pac power-fx repl

หลังจากนั้นคุณสามารถเรียกใช้คําสั่ง Power Fx ได้

ตัวอย่าง

ตัวอย่างต่อไปนี้แสดงการใช้ pac power-fx repl คําสั่ง

เพิ่มแถว
Collect(Contacts, { firstname: "Patti", lastname: "Fernandez" })

การตอบกลับ Power Fx จะตอบสนองดังต่อไปนี้:

{contactid:GUID("118d7b47-8f80-ee11-8179-0022482a40c7"), fullname:"Patti Fernandez", ...}
ความช่วยเหลือ

เรียกใช้คําสั่งต่อไปนี้เพื่อขอความช่วยเหลือเกี่ยวกับคําสั่งทั้งหมดที่มีอยู่ใน Power Fx repl:

Help()

Power Fx repl ตอบสนองกับเอาต์พุตต่อไปนี้:

  Abs             Acos            Acot            AddColumns      And
  Asin            AsType          Atan            Atan2           Average
  Blank           Boolean         Char            Clear           ClearCollect
  Coalesce        Collect         ColorFade       ColorValue      Concat
  Concatenate     Cos             Cot             Count           CountA
  CountIf         CountRows       Date            DateAdd         DateDiff
  DateTime        DateTimeValue   DateValue       Day             Dec2Hex
  Decimal         Degrees         Distinct        DropColumns     EDate
  EncodeUrl       EndsWith        EOMonth         Error           Exp
  Filter          Find            First           FirstN          Float
  ForAll          GUID            Help            Hex2Dec         Hour
  If              IfError         Index           Int             IsBlank
  IsBlankOrError  IsEmpty         IsError         IsMatch         IsNumeric
  IsToday         Language        Last            LastN           Left
  Len             Ln              Log             LookUp          Lower
  Match           MatchAll        Max             Mid             Min
  Minute          Mod             Month           Not             Notify
  Now             OptionSetInfo   Or              ParseJSON       Patch
  Pi              PlainText       Power           Proper          Radians
  Rand            RandBetween     Refresh         Remove          Replace
  RGBA            Right           Round           RoundDown       RoundUp
  Second          Sequence        Set             Shuffle         Sin
  Sort            Split           Sqrt            StartsWith      StdevP
  Substitute      Sum             Switch          Table           Tan
  Text            Time            TimeValue       TimeZoneOffset  Today
  Trim            TrimEnds        Trunc           Upper           Value
  VarP            Weekday         With            Year
>>

Note

คําสั่งเหล่านี้จะเปลี่ยนแปลงเมื่อเวลาผ่านไปเพื่อรวมคําสั่งเพิ่มเติม ซึ่งควรถูกซิงโครไนซ์กับคําสั่งที่มีในเอกสารอยู่ในปัจจุบัน

ออก

ใช้ Exit() เพื่อออกจาก repl คําสั่ง

เรียกใช้ pac power-fx

(ตัวอย่าง) เรียกใช้ไฟล์ของคําแนะนํา Power Fx

ตัวอย่าง

ตัวอย่างต่อไปนี้แสดงการใช้ pac power-fx run คําสั่ง

Note

ในแต่ละตัวอย่างเหล่านี้ คุณจําเป็นต้อง:

  1. สร้างไฟล์ที่มีชื่อด้วยtest-pfx.txtนิพจน์ Power Fx ในโฟลเดอร์บนคอมพิวเตอร์ของคุณ เช่นc:\test

  2. เปิดหน้าต่าง Windows PowerShell นําทางไปยังtestโฟลเดอร์ และใช้runคําสั่งที่ระบุไฟล์ที่มีคําสั่ง: pac power-fx run --file test-pfx.txt

หากต้องการใช้ตาราง Dataverse คุณจะต้องสร้างและเลือกโปรไฟล์การรับรองความถูกต้อง ดู การสร้างการรับรองความถูกต้อง pac และเลือกการรับรองความถูกต้อง pac

ถ้าคุณได้รับข้อผิดพลาด ให้ตรวจสอบ การแก้ไขปัญหา

สร้างระเบียน Dataverse

  1. เพิ่มข้อความต่อไปนี้ลงใน test-pfx.txt และบันทึกไฟล์

    Collect(Contacts, { firstname: "Megan", lastname: "Bowen" })
    Collect(Contacts, { firstname: "Garth", lastname: "Forth" })
    Collect(Contacts, { firstname: "Adele", lastname: "Vance" })
    Collect(Contacts, { firstname: "Patti", lastname: "Fernandez" })
    
  2. เรียกใช้คําสั่งนี้:

    PS C:\test> pac power-fx run --file test-pfx.txt
    

    คุณสามารถคาดหวังผลลัพธ์ดังต่อไปนี้:

    {contactid:GUID("80eb0c02-9180-ee11-8179-0022482a40c7"), fullname:"Megan Bowen", ...}
    {contactid:GUID("81eb0c02-9180-ee11-8179-0022482a40c7"), fullname:"Garth Forth", ...}
    {contactid:GUID("82eb0c02-9180-ee11-8179-0022482a40c7"), fullname:"Adele Vance", ...}
    {contactid:GUID("83eb0c02-9180-ee11-8179-0022482a40c7"), fullname:"Patti Fernandez", ...}
    

คิวรีตาราง Dataverse

  1. เพิ่มข้อความนี้ไปยัง test-pfx.txt และบันทึกไฟล์

    FirstN(Contacts, 5)
    

    คําสั่งนี้ดึงข้อมูลผู้ติดต่อห้าอันดับแรกจาก Dataverse

  2. เรียกใช้คําสั่งนี้:

    PS C:\test> pac power-fx run --file test-pfx.txt
    

    คุณสามารถคาดหวังผลลัพธ์ดังต่อไปนี้:

    Connected to... Your Organization
    Connected as you@yourorg.onmicrosoft.com
    
    contactid                                      fullname           ...
    ============================================== ================== =====
    GUID("eeb27495-d127-ed11-9db1-00224804f8e2")   Yvonne McKay (sample)
    GUID("cba0ed9e-d127-ed11-9db1-00224804f8e2")   Susanna Stubberod (sample)
    GUID("cea0ed9e-d127-ed11-9db1-00224804f8e2")   Nancy Anderson (sample)
    GUID("6cc7483c-7a77-ee11-8179-00224809f375")   Maria Campbell (sample)
    GUID("49b0be2e-d01c-ed11-b83e-000d3a572421")   Sidney Higa (sample)
    PS C:\test>
    

ใช้ฟังก์ชัน PowerFx

  1. เพิ่มข้อความต่อไปนี้ลงใน test-pfx.txt และบันทึกไฟล์

    Set(x, 1)
    Result = If( Mid( "asdf",x,1 ) = "a", "X", "Y" )
    

    ตัวอย่างนี้ใช้ฟังก์ชัน Mid, If และ Set Power Fx

  2. เรียกใช้คำสั่งต่อไปนี้

    PS C:\test> pac power-fx run --file test-pfx.txt
    

    คุณสามารถคาดหวังผลลัพธ์ดังต่อไปนี้:

    PS C:\test> pac power-fx run --file test-pfx.txt
    x: 1
    true
    Result: "X"
    PS C:\test>
    
  3. --echoเพิ่มพารามิเตอร์ และคุณสามารถคาดหวังผลลัพธ์นี้:

    PS C:\test> pac power-fx run --file test-pfx.txt --echo
    Set(x, 1)
    
    x: 1
    true
    Result = If( Mid( "asdf",x,1 ) = "a", "X", "Y" )
    
    Result: "X"
    PS C:\test>
    

พารามิเตอร์ที่จําเป็นสําหรับการเรียกใช้ power-fx

--file -f

เส้นทางของไฟล์ที่จะดําเนินการ

พารามิเตอร์ทางเลือกสําหรับการเรียกใช้ power-fx

--echo -e

True ถ้าคําสั่งอินพุตควร echo กลับไปยังเอาต์พุต

พารามิเตอร์นี้ไม่จําเป็นต้องมีค่า มันเป็นการสลับ

--environment -env

ระบุ Dataverse เป้าหมาย ค่าอาจเป็น Guid หรือ https URL แบบสัมบูรณ์ เมื่อไม่ได้ระบุ องค์กรที่ใช้งานอยู่ที่เลือกสําหรับโพรไฟล์การรับรองความถูกต้องปัจจุบันจะถูกใช้

การแก้ไขปัญหา

ต่อไปนี้คือขั้นตอนในการแก้ไขปัญหาข้อผิดพลาดที่คุณอาจพบเมื่อใช้ pac power-fx คําสั่ง

ข้อผิดพลาดเมื่อไม่มีโปรไฟล์การรับรองความถูกต้อง Dataverse

คุณสามารถได้รับข้อผิดพลาดเช่นนี้เมื่อคุณไม่มีโปรไฟล์การรับรองความถูกต้องสากลที่เชื่อมโยงกับสภาพแวดล้อม Dataverse

PS C:\test> pac power-fx run --file test-pfx.txt
Error 8-16: Name isn't valid. 'Contacts' isn't recognized.
Error 18-59: The specified column 'firstname' does not exist.
Error 0-60: The function 'Collect' has some invalid arguments.
Error 8-16: Name isn't valid. 'Contacts' isn't recognized.
Error 18-59: The specified column 'firstname' does not exist.
Error 0-60: The function 'Collect' has some invalid arguments.
Error 8-16: Name isn't valid. 'Contacts' isn't recognized.
Error 18-59: The specified column 'firstname' does not exist.
Error 0-60: The function 'Collect' has some invalid arguments.
Error 8-16: Name isn't valid. 'Contacts' isn't recognized.
Error 18-63: The specified column 'firstname' does not exist.
Error 0-64: The function 'Collect' has some invalid arguments.

เมื่อต้องการแก้ไขข้อผิดพลาดเช่นนี้ ให้สร้างโปรไฟล์การรับรองความถูกต้องสากลที่เชื่อมโยงกับสภาพแวดล้อม Dataverse

  1. เรียกใช้ รายการการรับรองความถูกต้อง pac ของคําสั่ง

    คุณอาจเห็นผลลัพธ์ดังต่อไปนี้ที่มี UNIVERSAL โปรไฟล์การรับรองความถูกต้องที่ไม่มี Url ที่ระบุว่ามีสภาพแวดล้อม Dataverse

    Index Active Kind      Name Friendly Name Url User                Cloud  Type
    [1]   *      UNIVERSAL                        you@yourcompany.com Public OperatingSystem
    

    ไม่เพียงพอเนื่องจากไม่ได้ระบุสภาพแวดล้อม Dataverse

  2. ใช้ การรับรองความถูกต้อง pac สร้าง โปรไฟล์ UNIVERSAL การรับรองความถูกต้องที่เชื่อมต่อกับสภาพแวดล้อม Dataverse

    Note

    --environmentใช้พารามิเตอร์โดยใช้ค่า environmentid ค้นหา ID สภาพแวดล้อมของคุณ

    อย่าใช้--urlพารามิเตอร์เนื่องจากจะสร้างโปรไฟล์แทนที่จะเป็นDATAVERSEUNIVERSALโปรไฟล์

    เช่น:

    PS C:\test> pac auth create --environment f2cef599-b112-4803-bb5d-090077017685 --name ConnectionName
    'you@yourcompany.onmicrosoft.com' authenticated successfully.
    Validating connection...
    Default organization: YourOrganization
    Connected to... YourOrganization
    Connected as you@yourcompany.onmicrosoft.com
    Authentication profile created
       * UNIVERSAL ConnectionName                 https://yourcompany.crm.dynamics.com/          : you@yourcompany.onmicrosoft.com              Public
    
    PS C:\test>
    
  3. เรียกใช้ รายการการรับรองความถูกต้อง pac อีกครั้ง คุณควรเห็นผลลัพธ์ที่มี UNIVERSAL โปรไฟล์การเชื่อมต่อด้วย URL สําหรับสภาพแวดล้อม Dataverse ของคุณ

    PS C:\test> pac auth list
    Index Active Kind      Name           Friendly Name        Url                                   User                  Cloud  Type
    [1]   *      UNIVERSAL                                                                           you@yourcompany.com   Public OperatingSystem
    [2]   *      UNIVERSAL ConnectionName YourOrganization     https://yourcompany.crm.dynamics.com/ you@yourcompany.com   Public User
    
    PS C:\test>
    
  4. เลือกUNIVERSALสภาพแวดล้อมเพื่อทําให้เป็นโปรไฟล์เริ่มต้นโดยใช้คําสั่งเลือกการรับรองความถูกต้อง pac

    PS C:\test> pac auth select --index 2
    New default profile:
       * UNIVERSAL ConnectionName                 https://yourcompany.crm.dynamics.com/          : you@yourcompany.com              Public
    
    PS C:\test>
    

ดูเพิ่มเติม

กลุ่มคําสั่ง Microsoft Power Platform CLI
ภาพรวม Microsoft Power Platform CLI